Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utcsri!utgpu!romwa From: romwa@gpu.utcs.toronto.edu Newsgroups: comp.unix.questions Subject: Re: sed - match newlines on input Message-ID: <1987Mar10.180919.2869@gpu.utcs.toronto.edu> Date: Tue, 10-Mar-87 18:09:19 EST Article-I.D.: gpu.1987Mar10.180919.2869 Posted: Tue Mar 10 18:09:19 1987 Date-Received: Tue, 10-Mar-87 21:00:00 EST References: <570@hao.UCAR.EDU> Organization: University of Toronto Computing Services Lines: 28 Keywords: imbedded newline, broke! Checksum: 03942 Summary: Not sed, but tr. Sed and newlines don't work for me In article <570@hao.UCAR.EDU>, bill@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 > I have always had trouble with newlines and sed. The way I would deal with your problem is to use 'tr' and then sed. It would go something like this: tr "\012" "#" < datafile | sed -e 's/#/, /g' > outfile This translates all new lines to a printable ascii character. You should use one that does not occur elswhere in the file. The output is piped to sed where the character '#' is expanded to ', '. I, too, would like to see a sed example doing the whole process.