sed script to combine blank lines? (sed + awk solutions)

Maarten Litmaath maart at cs.vu.nl
Sat Oct 15 06:32:04 AEST 1988


In article <7372 at megaron.arizona.edu> rupley at arizona.edu (John Rupley) writes:
\sed   "/^[<sp><tab><lf>]*$/{
\	N
\	/\n.*[^<sp><tab><lf>]/{
\	b
\	}
\	D
\	}" filename

Four things:
1)	I guess you meant <ff>, instead of <lf>.
2)	The script doesn't convert lines containing [<sp><tab><ff>]* to JUST
	1 newline.
3)	The script contains non-printable characters.
4)	The script could have been less complex.

For these reasons I suggest the following adjusted script:

------------------------------cut here----------------------------------------
#! /bin/sh

chars=" `echo tf | tr tf '\11\14'`"
exec sed "/^[$chars]*$/{
		N
		/\n[$chars]*$/D
		s/[$chars]*//
	}" $*
------------------------------cut here----------------------------------------

The `awk' solution I posted earlier, had to be modified a bit too:

------------------------------cut here----------------------------------------
#! /bin/sh

exec awk '$0 !~ /^[ \t\f]*$/ { print; prev = 0; next }
	prev == 0 { prev = 1; print "" }' $*
-- 
Hippic sport:                         |Maarten Litmaath @ Free U Amsterdam:
             a contradiction in terms.|maart at cs.vu.nl, mcvax!botter!maart



More information about the Comp.unix.questions mailing list