sed behaves differently when run in backquotes/subshell

Maarten Litmaath maart at cs.vu.nl
Tue Aug 8 03:38:26 AEST 1989


stever at tree.UUCP (Steve Rudek) writes:
\...
\GUESSES=`cat .TST | sed 's/\(.\)/\1\
\/g'|sort|paste -s -d"\0" -`

Inside backquotes escaped newlines are removed...
Now sed `sees' the following argument:

	s/\(.\)/\1/g

To protect the escaped newline:

	... | sed 's/\(.\)/\1\\

That's right: ONE extra backslash suffices - newlines are left undisturbed
inside single quotes.
In general, to debug pipe lines try something like:

	GUESSES=`cat .TST | echo sed 's/\(.\)/\1\
	/g' > /dev/tty | sort | ...`

i.e. just insert "echo" and "> /dev/tty" to see what the funny stuff expands
to.
-- 
"Mom! Eric Newton broke the day! In 24   |Maarten Litmaath @ VU Amsterdam:
  parts!" (Mike Schmitt in misc.misc)    |maart at cs.vu.nl, mcvax!botter!maart



More information about the Comp.unix.questions mailing list