net.unix
Mark Weiser
mark at umcp-cs.UUCP
Tue Oct 9 15:41:54 AEST 1984
> I was wondering if this is a chronic problem with sed. It
>seems that I cannot get sed to match patterns with an imbedded newline.
>I have talked to some other avid users of sed and they seem to have
>the same problem. According to the documentation, the sequence '\n'
>will match a newline imbedded in a string. So this is what I tried:
> I wanted to match:
> .ul
> followed by anything on the next line
> and convert it to
> \fIfollowed by anything on the next line\fR
> so I tried:
> sed 's/^\.ul\n\(.*\)$/\\fI\1\\fR/'
> I even tried simple examples to try to get it to work, but to
>no avail. Can anyone help me out?
>
Sure. The problem is that ordinarily sed only puts single lines in
its "pattern space". To get imbedded new lines in there you must
use the sed "N" command. To quote from the sed manual entry:
N Append the next line of input to the pattern space
with an embedded newline.
Here is a sed script that does what you want. It takes a slightly
more complicated form, worthy of placing in a file rather than on the
sed command line:
/^\.ul$/N
s/^\.ul\n\(.*\)$/\\fI\1\\fR/
--
Spoken: Mark Weiser ARPA: mark at maryland
CSNet: mark at umcp-cs UUCP: {seismo,allegra}!umcp-cs!mark
More information about the Comp.unix
mailing list