sed - match newlines on input

romwa at gpu.utcs.toronto.edu romwa at gpu.utcs.toronto.edu
Wed Mar 11 09:09:19 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
> 
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.



More information about the Comp.unix.questions mailing list