deleting some empty lines with sed

Rouben Rostamian rouben at math16.math.umbc.edu
Sun Apr 28 05:33:42 AEST 1991


In article <1991Apr27.143519.26256 at daimi.aau.dk> datpete at daimi.aau.dk (Peter Andersen) writes:
>I use sed to make a few changes to the text. I have figured
>most of it out, but I have one problem remaining:
>If two or more blank lines appear, I want to remove all but
>one of these.

This should do it:

sed -n -e '
/^ *$/!p
/^ *$/{
    p
    :loop
    n
    /^ *$/bloop
    p
}'  <input_file

To catch and eliminate lines that have a mixture of tab and space characters,
you may want to modify this by replacing each of the /^ */ expressesions
by /^[ T]*$/, where I have typed a T to represent a tab.  (In other words,
you should type a tab where I have a T.)

Hope that this helps.

--
Rouben Rostamian                          Telephone: (301) 455-2458
Department of Mathematics and Statistics  e-mail:
University of Maryland Baltimore County   bitnet: rostamian at umbc.bitnet
Baltimore, MD 21228,  U.S.A.              internet: rouben at math9.math.umbc.edu



More information about the Comp.unix.shell mailing list