sed script to combine blank lines?
John Rupley
rupley at arizona.edu
Fri Oct 14 10:30:01 AEST 1988
In article <136 at nascom.UUCP>, rar at nascom.UUCP (Alan Ramacher) writes:
> In article <192 at vlsi.ll.mit.edu>, young at vlsi.ll.mit.edu (George Young) writes:
> > Is there a 'sed' wizard out there? I often want to take a big ascii file
> > (like a .c file after cc -E) and collapse each group of 'blank' lines
> > into exactly one blank line. 'Blank' here is any combination of blanks,
> > tabs and maybe ^L's.
>
> sed is not powerful enuf for the job, but a simple awk script will
> work.
The following simple sed script should work (after replacing <sp> etc
by the corresponding ascii characters) -- and I suspect it is shorter and
will run faster than an equivalent awk script.
sed "/^[<sp><tab><lf>]*$/{
N
/\n.*[^<sp><tab><lf>]/{
b
}
D
}" filename
John Rupley
internet: rupley at megaron.arizona.edu
uucp: ..{cmcl2 | hao!ncar!noao}!arizona!rupley
Dept. Biochemistry, Univ. Arizona, Tucson AZ 85721
More information about the Comp.unix.questions
mailing list