🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.editors
Article #3528

Re: SED Question

#3528
From: John Rupley
Date: Wed, 12 Apr 1989 10:47
75 lines
2618 bytes
In article <38564@bbn.COM>, jgrace@bbn.com (Joe Grace) writes:
> 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\</d   as far as I can tell, because
> >sed won't allow patterns to span lines.  Is there a way to do this, without
> >resorting to awk or ed?   
> 
> 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.

Sed can check for EOF, I believe, and fairly simply, by use of the
address "$", for last line of file.  The following script should take
care of the last line problem, as well as some additional but probably
not all other abnormalities. 

sed -e '/^PROMPT>$/{
	: restart
	/^PROMPT>$/{
		h
		$q
		N
		/^PROMPT>\n>$/{
			h
			$q
			N
			/^PROMPT>\n>\n<$/d
			x
			p
			x
			s/^PROMPT>\n>\n//
			b restart
		}
		x
		p
		x
		s/^PROMPT>\n//
		b restart
	}
}'


John Rupley
 uucp: ..{uunet | ucbvax | cmcl2 | hao!ncar!noao}!arizona!rupley!local
 internet: rupley!local@megaron.arizona.edu
 (H) 30 Calle Belleza, Tucson AZ 85716 - (602) 325-4533
 (O) Dept. Biochemistry, Univ. Arizona, Tucson AZ 85721 - (602) 621-3929
Technical Details
Message-ID: <10191@megaron.arizona.edu>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ames!ig!arizona!rupley
References: <2360001@hpcuhc.HP.COM> <38564@bbn.COM>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ames!ig!arizona!rupley
From: rupley@arizona.edu (John Rupley)
Newsgroups: comp.editors
Subject: Re: SED Question
Summary: sed not broken
Keywords: sed
Message-ID: <10191@megaron.arizona.edu>
Date: 12 Apr 89 10:47:42 GMT
References: <2360001@hpcuhc.HP.COM> <38564@bbn.COM>
Organization: U of Arizona CS Dept, Tucson
Lines: 75