Putting in newlines using sed

Chris Torek chris at umcp-cs.UUCP
Wed Nov 20 17:34:18 AEST 1985


Feeding `sed' newlines is easy; the real trick is getting the C shell
to hand it the right stuff.

The sed documentation says that in order to insert newlines in
substitute commands, you should quote them with backslash:

	sed -e 's/foo/b\
	a\
	r/'

Indeed, this works quite well in the Bourne shell, which does what
I consider the `proper' thing with this input.  The C shell, however,
thinks it is smarter than you are, and *removes* the trailing
backslashes!  So instead you must type

	sed -e 's/foo/b\\
	a\\
	r/'

Probably the best solution is to place your sed commands in a
separate file; then which shell is used no longer matters.
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 4251)
UUCP:	seismo!umcp-cs!chris
CSNet:	chris at umcp-cs		ARPA:	chris at mimsy.umd.edu



More information about the Comp.unix mailing list