[comp.unix.questions] Joining Lines in SED ?

wcs) (09/05/89)

A few months back there was a discussion  of things you could do
with sed, such as crunching multiple newlines.  Does anyone know
how to join lines using sed?  I've played around with the
hold-space buffer, and with 'y', but nothing's worked for me.

(I've also tried using ed/ex/vi scripts, but the file I've been
hacking is too large for this to work, and bfs doesn't appear to
have join.  I could stoop to using awk, but sed looks like about
the right tool, and not all my machines have samsed.)

			Thanks;  Bill
-- 
# Bill Stewart, AT&T Bell Labs 4M312 Holmdel NJ 201-949-0705 ho95c.att.com!wcs
# often found at 201-271-4712 tarpon.att.com!wcs Somerset CP3-4C423 fax469-1355
# Extremism in Defense of Liberty is No Substitute for Vice.

wcs@alice.UUCP (Bill Stewart, usually) (09/08/89)

In article <3559@cbnewsh.ATT.COM> wcs@cbnewsh.ATT.COM (Bill Stewart 201-949-0705 ho95c.att.com!wcs) writes:
:how to join lines using sed?  

Thanks to those of you who replied.  The answer was to do
	N	# append next input line to pattern space
	s/\n//	# trash the newline
It halfway worked.  The subtlety about this is the order in which
sed-commands are executed.  When I executed
	sed -e 's/old/new/' -e '/joinme/N' -e 's/\n/ /' <<!
	first line old stuff joinme
	second line old stuff
	!
the output was
	first line new stuff joinme second line old stuff
because the second line got appended to the pattern space
AFTER the substitution command.  Worked fine when I did
	sed -e '/joinme/N' -e 's/\n/ /' -e 's/old/new/' 

-- 
#				Thanks;
# Bill Stewart, att!ho95c!wcs, AT&T Bell Labs Holmdel NJ 1-201-949-0705