procmail
[Top] [All Lists]

Re: blank line consolodation/strippage

2001-11-19 11:23:20

On Sun, Nov 18, 2001 at 11:54:42PM -0800, Professional Software Engineering 
wrote:

I'm dead tired from a bunch of other scripting I've been doing 
recently.  I'm hoping someone else might already have a blank line compressor?
...
Also, something to trim ALL blanks which might trail a message.

Here's what I use:

| awk 'BEGIN { a=0; }
        a==0 { print; }
        a==0 && $0 ~ /^[        ]*$/ { a=1; next; }
        a==1 && $0 !~ /^[       ]*$/ { a=0; print; }'

This will shrink runs of more than one blank line down to one line, and
will therefore strip all but 1 trailing blanks.  When I first tried to
do this, I tried to use 'getline', but found that I'd have to do a bunch
of manual error handling to recognize EOF.  Setting the 'a' toggle seems
to work just fine.  The 'next' on line 3 is just for performance; if
that line has been hit, the next one definitely won't be, so there's no
point in devoting resources to testing its conditions.

Something whereby multiple blank lines (such as the above) might be 
compressed down to at most 2 or 3 blank lines, to retain spacing flavour in 
a message, while still compressing the dead space.

If you want to leave 2 or 3 blank lines in places, that would require
code which I haven't already written.  ;-)

Minimal overhead is preferred - this is taking place on list processing for 
a lot of messages each day across multiple mailing lists.

I'm sure this could also be done in a sed script, but awk is low enough
overhead for even my highest traffic lists.


-- 
  Paul Chvostek                                             
<paul(_at_)it(_dot_)ca>
  Operations / Development / Abuse / Whatever       vox: +1 416 598-0000
  IT Canada                                            http://www.it.ca/

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