sed script to combine blank lines?

Mark Salyzyn mark at adec23.UUCP
Tue Oct 18 01:57:25 AEST 1988


In article <192 at vlsi.ll.mit.edu>, young at vlsi.ll.mit.edu (George Young) writes:
> 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.  It looks from the documentation that sed should do this
> quite neatly, using the multiple line pattern space commands with imbedded
> newlines, but I sure can't figure out how.  I'd prefer the resulting blank
> line to be just a newline.

This is untested, but you should get the idea ...

: loop
N
/^[(blank)(tab)(form feed)]*\n[(blank)(tab)(form feed)]*$/ {
s///
b loop
}

Replace (blank) with the blank character itself. Replace (tab) with the tab
character itself. Replace (form feed) with the form feed character itself.

-- Mark Salyzyn @ ADEC Systems Inc.



More information about the Comp.unix.questions mailing list