procmail
[Top] [All Lists]

Re: blank line consolidation/strippage

2001-11-24 20:27:58
(resent to the list - doh!)

At 10:37 2001-11-24 -0600, David W. Tamkin did say:

Sean wants to reduce all runs of three or more blank lines to two, and
that's more easily done in perl or perhaps *awk than in sed, unless, as I
posted earlier, one can be positive that the entire text will fit into sed's
hold space.

#---------------------------------------------------------------
# reducer.rc
#

# take lines consisting solely of whitespace and make them just newlines,
# and while doing so, take runs of more than 2 blank lines and reduce them to
# just 2 blank lines.  This should help reduce large swathes of empty space
# (often at the footer of some messages).

# THIS IS NOT INTENDED TO BE RUN ON MESSAGES WHICH CONTAIN ATTACHMENTS!

# We don't run this conversion on PGP signed messages, so as to avoid
# clobbering signed data.

# disable SHELLMETAS so the following sed invocation doesn't involve an
# extra shell
# save the value in another variable
savemetas=$SHELLMETAS
# disconnected variable name unsets it
SHELLMETAS

:0fb
* ! B ?? ^-----BEGIN PGP SIGNED MESSAGE-----
|sed -e '/^[ ]*$/{;s/[ ]*//;N;/^\n[ ]*$/{;s/^\(\n\)\([ ]*\)$/\1/;:nexblank;N;/^\n\n[ ]*$/{;s/^\(\n\)\(\n[ ]*\)$/\1/;t nexblank;};};}'

# restore original value and clear the save copy
SHELLMETAS=$savemetas
savemetas

#---------------------------------------------------------------

(that's one continuous sed line from "|sed" through "nexblank...")

Thanks to the input from several people here, it's working. Now, just to convince my associate that modifying messages in this way (to improve digests and archives) doesn't really constitute changing the message (I say it doesn't change the context).

Oh, I didn't reply to David's previous post:

There are two other approaches besides having the instructions in a separate
file:

1. Use repeated -e options, one for each instruction.
2. If your sed groks semicolons, string instructions together with
semicolons instead of newlines.

I ran into some difficulty with the first method, but that may have related more to my having to use a -f for the multiline condensing.

Semicolons saved the day, as seen above.  This was also suggested by Martin.

---
 Sean B. Straw / Professional Software Engineering

 Procmail disclaimer: <http://www.professional.org/procmail/disclaimer.html>
 Please DO NOT carbon me on list replies.  I'll get my copy from the list.

_______________________________________________
procmail mailing list
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail

<Prev in Thread] Current Thread [Next in Thread>