deleting some empty lines with sed
Larry Wall
lwall at jpl-devvax.jpl.nasa.gov
Fri May 3 05:11:57 AEST 1991
In article <281DB41B.9E6 at marob.uucp> daveh at marob.uucp (Dave Hammond) writes:
: Perhaps I'm oversimplifying the problem, but wouldn't
:
: tr -s '\012'
:
: squeeze multiple, consecutive newlines to a single newline?
Yes, it would, and yes, you are. They wanted to squeeze 3 or more
consecutive newlines down to 2.
Incidentally, with perl 3.044 and later you can do it with
perl -00pe 's/^\n+//'
or, less efficiently (because of file slurping overhead and string copying
due to modifying the middle of a long string, and because the previous
solution uses anchored search),
perl -0777pe 's/\n{3,}/\n\n/g'
Oddly enough, any octal number will work in place of 0777 except 012, which
would set the input delimiter to newline.
Larry Wall
lwall at netlabs.com
More information about the Comp.unix.shell
mailing list