Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10 5/3/83; site sequent.UUCP Path: utzoo!watmath!clyde!burl!ulysses!mhuxj!houxm!vax135!cornell!uw-beaver!tektronix!ogcvax!sequent!merlyn From: merlyn@sequent.UUCP Newsgroups: net.unix Subject: Re: net.unix Message-ID: <544@sequent.UUCP> Date: Mon, 8-Oct-84 14:43:50 EDT Article-I.D.: sequent.544 Posted: Mon Oct 8 14:43:50 1984 Date-Received: Tue, 9-Oct-84 04:17:22 EDT References: <1977@stolaf.UUCP> Organization: Sequent Computer Systems, Portland Lines: 52 > From: berge@stolaf.UUCP > Message-ID: <1977@stolaf.UUCP> > Date: Fri, 5-Oct-84 17:06:20 PDT > > 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? Yeah, I can help you out. Which way did you come in? :-) [it's monday folks!] Embedded newlines ONLY show up in the pattern space when you do something fancier than just s/this/that/ stuff. One way is if you substitute them in, like s/this/that\ and that/ in which case, a later /that\nandthat/ will match what's in the pattern space. Remember, sed works on a LINE AT A TIME unless you tell it otherwise. A solution to your problem might take the form of: sed -n ' /^\.ul/{ n (discard current line; fetch next) s/.*/\\fI&\\fR/ (insert nroff blather) } p' (print regardless) Yeah, not an easy solution, but it works (oops.. untested though... just relying on old information!). The reason for the sed -n and then the later p is a bit esoteric... you don't want the 'n' command to print the '.ul', and using a 'd' inside curly braces aborts the current cycle too early. (Skip that if you can't follow it... just comes from having written rather LONG sed scripts.) Write me directly if you want further help. I can get long-winded about UNIX language (yes, sed is a language! :-) solutions. -- A particularly personal and original observation from the thought-stream of Randal L. ("s/nothing/something/p") Schwartz, esq. (merlyn@sequent.UUCP) (Former Official Legendary Sorcerer of the 1984 Summer Olympics) Sequent Computer Systems, Inc. (503)626-5700 (sequent = 1/quosine) UUCP: {decwrl,ogcvax,pur-ee,rocks34,shell,unisoft,vax135,verdix}!sequent!merlyn Original Material (C) 1984 by Randal L. Schwartz [ALL RIGHTS RESERVED]