Joining Lines in SED ?
Bill Stewart, usually
wcs at alice.UUCP
Sat Sep 9 00:29:19 AEST 1989
In article <3559 at cbnewsh.ATT.COM> wcs at 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
More information about the Comp.unix.wizards
mailing list