sed - match newlines on input (the answer)

allyn at sdcsvax.UUCP allyn at sdcsvax.UUCP
Thu Mar 12 05:23:30 AEST 1987


In article <570 at hao.UCAR.EDU>, bill at hao.UCAR.EDU (Bill Roberts) wants to
use sed to match a pattern over multiple lines.

the trick to sed is that you need to tell it when to join the lines
before it can look for multiple line patterns.  the N command is
used for this.

try this command:

sed -f sedinput < inputfile

with the "sedinput" file containing:
/^one$/N
/^one\ntwo$/N
/^one\ntwo\nthree$/s/\n/, /g

with an "inputfile" consisting of:
zero
one
two
three
four

it produces as output:
zero
one, two, three
four

-- 
 From the virtual mind of Allyn Fratkin            allyn at sdcsvax.ucsd.edu    or
                          EMU Project              {ucbvax, decvax, ihnp4}
                          U.C. San Diego                         !sdcsvax!allyn



More information about the Comp.unix.questions mailing list