Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site umcp-cs.UUCP Path: utzoo!linus!philabs!cmcl2!seismo!umcp-cs!mark From: mark@umcp-cs.UUCP (Mark Weiser) Newsgroups: net.unix Subject: Re: net.unix Message-ID: <276@umcp-cs.UUCP> Date: Tue, 9-Oct-84 01:41:54 EDT Article-I.D.: umcp-cs.276 Posted: Tue Oct 9 01:41:54 1984 Date-Received: Wed, 10-Oct-84 06:06:33 EDT References: <1977@stolaf.UUCP> Organization: U of Maryland, Computer Science Dept., College Park, MD Lines: 30 > 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@maryland CSNet: mark@umcp-cs UUCP: {seismo,allegra}!umcp-cs!mark