| 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
will reduce all runs of empty line; it will preserve a single empty line at
the bottom if there is one there to start. Some versions of cat have a -s
switch to do that (in other cats, -s does something unrelated), but I don't
recomend that because it will also keep one empty line at the top if there
is no text on the top line of the input.
I used to run my list through
sed -e 's/[ ][ ]*$//' -e '/./,/^$/!d'
to strip trailing whitespace from the right margins and then to squeeze runs
of empty lines. That had the extra benefit of reducing non-empty lines of
nothing but whitespace to emptiness and including them in the squeezing.
Whenever the question of squeezing runs of empty lines into one empty line
comes up in netnews, invariably three wrong solutions are posted:
1. sed '/^$/d'
2. tr -s '\012'
3. tr -d '\012'
The first two remove all empty lines and make a single block of text. The
third removes all line breaks and makes the text into one long line!
If it is essential to strip all empty lines from the bottom, it gets more
complicated. I figured it out way back in the day but don't remember it
now; it was not just a variation on the code above. Normally, though, one
wants a single empty line at the foot of a message body in email.
procmail mailing list