[comp.unix] getting sed to put linefeed in output stream

bm@bike2work.Eng.Sun.COM (Bill Michel) (10/11/90)

I want to put a newline in my output with sed. Something like

sed "/NAME */NAME \n/" inputfile

in other words, replace each occurrence of NAME followed by one or more
spaces with NAME followed by a newline. \n doesn't quite seem to do
it, however, and I get a literal "n" in my output. I have been able
to embed a carriage return (^M) but not a linefeed (it doesn't show
up as a control character, but rather, breaks the line in the script.

HELP!

bill@camco.Celestial.COM (Bill Campbell) (10/17/90)

In article <2199@megadon.UUCP> bm@bike2work.Eng.Sun.COM (Bill Michel) writes:
:I want to put a newline in my output with sed. Something like
:
:sed "/NAME */NAME \n/" inputfile
:
:in other words, replace each occurrence of NAME followed by one or more
:spaces with NAME followed by a newline. \n doesn't quite seem to do
:it, however, and I get a literal "n" in my output. I have been able
:to embed a carriage return (^M) but not a linefeed (it doesn't show
:up as a control character, but rather, breaks the line in the script.
:
:HELP!

One way to do this is:
	sed '
		s/NAME */NAME\
/g
' inputfile

The backslash at the end of the line escapes the newline.
-- 
INTERNET:  bill@Celestial.COM   Bill Campbell; Celestial Software
UUCP:   ...!thebes!camco!bill   6641 East Mercer Way
             uunet!camco!bill   Mercer Island, WA 98040; (206) 947-5591