Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!bbn!bbn.com!jgrace From: jgrace@bbn.com (Joe Grace) Newsgroups: comp.editors Subject: Re: SED Question Summary: sed is broken Keywords: sed Message-ID: <38564@bbn.COM> Date: 12 Apr 89 00:11:35 GMT References: <2360001@hpcuhc.HP.COM> Sender: news@bbn.COM Reply-To: jgrace@BBN.COM (Joe Grace) Organization: Bolt Beranek and Newman Inc., Cambridge MA Lines: 47 In article <2360001@hpcuhc.HP.COM> smaxwell@hpcuhc.HP.COM (Susan Maxwell) writes: > >Got a sed question for you: I'm creating a sed filter to mask out and >delete unwanted characters in a trace file. I'm having trouble with this >configuration: > > LINE I: PROMPT> > LINE I+1: > > LINE I+2: < > >Whenever I see this series, I want to delete ALL THREE lines. I can't >create a pattern /PROMPT\>\\n\>\\n\sed won't allow patterns to span lines. Is there a way to do this, without >resorting to awk or ed? > >Susan Maxwell Yes, there is a way to get sed to do this, but you have to be wary of sed's shortcomings. Try: ---- #! /bin/sh (cat trace.out; echo "SomeUniqueID") \ | sed \ -e '/^PROMPT>$/{' \ -e 'N' \ -e '/\nSomeUniqueID$/{;s@\nSomeUniqueID$@@;q;}' \ -e 'N' \ -e '/\nSomeUniqueID$/{;s@\nSomeUniqueID$@@;q;}' \ -e '/^PROMPT>\n>\n<$/d' \ -e '}' \ -e '/^SomeUniqueID$/d' If sed had a way of handling an EOF without quitting, the SomeUniqueID would be unnecessary. As sed is, the SomeUniqueID is used to avoid losing lines which start out the same as your pattern but which do not fully match your pattern --- and which you therefore want to keep. Cheers, = Joe = Joe Grace ARPA: jgrace@bbn.com UUCP: {harvard,husc6,decvax,etc.}!bbn!jgrace