procmail
[Top] [All Lists]

Re: SED -- Delete successive blank lines

2000-03-04 14:52:30
2000-03-04-13:28:27 David W. Tamkin:
How can I tell SED to replace any three successive paragraph
marks (new line & carriage return) with a single one?

First question: three consecutive ends-of-line mean two blank
lines; are you asking how to reduce any run of two or more blank
lines to a single blank line?  If you reduce them to a single
end-of-line you'll lose all blank lines, period, and get one solid
block of text.  I doubt that you meant that. [...]

I don't know what the original poster was asking for, but just as a
possible guess, if he's hoping to do cleanup of scruffy text files
so they're leaner and meaner and less wasteful of his screen real
estate, perhaps the easy -n- sleazy fix would be to pipe them
through uniq? My routine and habitual cleanup looks something like

        perl -ple 's/^\s+//;s/\s+$//;s/\s+/ /g'|uniq

to clobber bogus leading and trailing whitespace, and compress all
the rest, then clobber duplicate successive lines (including in
particular whitespace ones). Sometimes, depending on the content, I
also toss in something like 's/^(.)\1\1\1+$/\1\1\1/' to reduce fancy
lines of dashes or underscores or asterisks. This sort of cleanup
makes docs far friendlier to e.g. pack into doc or isilo and send to
a palm pilot:-).

-Bennett

Attachment: pgpRsyH2aUSBz.pgp
Description: PGP signature