Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watnot!watmath!clyde!rutgers!sri-spam!ames!hao!bill From: bill@hao.UUCP Newsgroups: comp.unix.questions Subject: The solution to the sed - multiple lines problem Message-ID: <574@hao.UCAR.EDU> Date: Wed, 11-Mar-87 19:11:50 EST Article-I.D.: hao.574 Posted: Wed Mar 11 19:11:50 1987 Date-Received: Fri, 13-Mar-87 01:50:00 EST Organization: High Altitude Obs./NCAR, Boulder CO Lines: 33 This is the solution of the "sed - matching multiple lines on input" problem which I posed a few days ago. I thought I'd post it to the net to let people know I've solved it and just how to do it. Given the following input: one two three and the following sed editor script: s/one\ntwo\nthree/one, two, three/g Why don't it work? Well here's my hypothesis: Sed reads the first line which contains the string "one\n" and discards the newline. So the pattern space looks like "one". Of course the pattern "one\ntwo\nthree" won't match that. So the second line gets read and the same thing happens, then the third line and so nothing ever matches. The solution was to build up the pattern space by using the "hold buffer". The following sed script does the job: /one/!b N /two/!b N /three/!b s/\n/, /g See the sed writeup to understand the commands !, b and N. Thanks to all who responded with positive suggestions. --Bill