sed - match newlines on input

tj at mks.UUCP tj at mks.UUCP
Thu Mar 12 09:37:48 AEST 1987


In article <570 at hao.UCAR.EDU>, bill at hao.UCAR.EDU (Bill Roberts) writes:
> I'm trying to match a pattern over multiple lines.  For instance, on the input:
>	one
>	two
>	three
> with the sed script:
>	s/one\ntwo\nthree/one, two, three/g
> one would expect to get the following output
>	one, two, three
> OK, so I don't understand the manual (what else is new).  How can I get what I
> need?  Also, what about the "Multiple Input-line Functions".  Might that be the
> way to go?  An example would really help.  Thanks in advance.

sed -e '/one$/{
N
N
s/one\ntwo\nthree/one, two, three/
}'

This solution was found without effort on the first attempt.
Perhaps MKS Toolkit documentation is better than some...
;-)

     ll  // // ,~/~~\'   T. J. Thompson {decvax,ihnp4,seismo}!watmath!mks!tj
    /ll/// //l' `\\\     Mortice Kern Systems Inc.
   / l //_// ll\___/     43 Bridgeport Rd. E., Waterloo, ON, Can. N2J 2J4
O_/                      (519)884-2251
-- 
     ll  // // ,~/~~\'   T. J. Thompson {decvax,ihnp4,seismo}!watmath!mks!tj
    /ll/// //l' `\\\     Mortice Kern Systems Inc.
   / l //_// ll\___/     43 Bridgeport Rd. E., Waterloo, ON, Can. N2J 2J4
O_/                      (519)884-2251



More information about the Comp.unix.questions mailing list