procmail
[Top] [All Lists]

Re: blank line consolodation/strippage

2001-11-23 20:29:37
(Had this sitting around and finally had a chance to think about it.)

On Mon, 19 Nov 2001, Professional Software Engineering wrote:

To do what I want (anything more than 2 blank lines, consolodated to just 
2, plus reduce all-whitespace lines to just a newline), I've got to use the 
following somewhat awkward (I'm not keen on commands which must flow 
between lines) sed invocation:

# executed from within some other condition block
:0f
* ! B ?? ^-----BEGIN PGP SIGNED MESSAGE-----
| sed -e 's/^[  ][      ]*$//'|sed -e '/^$/N \
         /^\n$/{N \
                 /^\n\n$/D \
}'

An easier way to do the second part of that is:

sed -n -e '/./,/^$/{/^$/N;p;}'

That is, always print the next line after any blank line, whether that
next line is blank or not.

I'd also like to combine these two invocations into one

That's harder, but you can derive it from the above.  First, replace the
starting and ending patterns with "anything but a space" and "any line
consisting of zero or more spaces", then use 'p;n;p' instead of 'N;p' so
that there are never embedded newlines in the pattern space, and finally
do the substitution after each line is read (which means repeating it
after explictly reading one).

sed -n -e '/[^  ]/,/^[  ]*$/{s/^[       ]*$//;p;/^$/!d;n;s/^[   ]*$//;p;}'

Note that in your original substitution
        s/^[    ][      ]*$//
it's useless to search for "at least one space or tab" if you're just
going to delete all of them anyway.  Either you meant
        s/^\([  ]\)[    ]*$/\1/
or the number of spaces doesn't matter and you can just use
        s/^[    ]*$//
which is what I did.

_______________________________________________
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>