[Chicago-talk] Replacing consecutive newlines with a single newline

Steven Lembark lembark at wrkhors.com
Sun Sep 28 14:16:11 PDT 2008

Vijay Kumar wrote:
> Sorry for not being clear about the problem. The intention was to
> replace consecutive 2+ multiple blank lines with 2 blank lines.
> Today I checked-in some code like below that formats Oracle's spool output.
>     perl -0777 -pi -e 's/^SQL>//mg; s/\n{2,}/\n\n/g' inputfile
>     cat inputfile | mailx ....
> and obviously giving credit to Andy in the comments and explaining about 0777.

All you are trying to do is remove blank lines.

     perl -n -e 'print if /./' $file


     perl -n -e 'print if /./' < $file

will do that with a minimum of command line
switches and regexen (not to mention cats).

Steven Lembark                                            85-09 90th St.
Workhorse Computing                                 Woodhaven, NY, 11421
lembark at wrkhors.com                                      +1 888 359 3508

More information about the Chicago-talk mailing list