🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.editors
Article #3541

Re: Re^2: SED Question

#3541
From: John Rupley
Date: Fri, 14 Apr 1989 02:14
65 lines
1592 bytes
In article <2292@solo11.cs.vu.nl>, maart@cs.vu.nl (Maarten Litmaath) writes:
> jgrace@bbn.com (Joe Grace) writes:

[the problem is to delete all three-line sequences:
		PROMPT>
		>
		<
]

> \...
> \Yes, there is a way to get sed to do this, but you have to be
> \wary of sed's shortcomings.
> 
> [shell script workaround deleted]
> 
> \If sed had a way of handling an EOF without quitting, the
> \[workaround would be unnecessary] [...]
> 
> My first sed attempt can easily be fixed to handle partial matches at EOF
> properly:

[sed script deleted]

Neat script (of course), but it still fails with a partial sequence
followed by a proper sequence, such as:

		PROMPT>
		>
		PROMPT>
		>
		<

The ``restart'' loop below takes care of it:

sed -n '
	: restart
	/^PROMPT>$/{
		h
		$p
		n
		/^>$/{
			H
			${x;p;}
			n
			/^<$/d
		}
		x
		p
		x
		b restart
	}
	p
'

BTW -- the following one line Lex source does it all:

%%
PROMPT>\n>\n<\n		;

and its hard to get the logic wrong (:-)!


John Rupley
rupley!local@megaron.arizona.edu
Technical Details
Message-ID: <10244@megaron.arizona.edu>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!agate!bionet!ig!arizona!rupley
References: <2360001@hpcuhc.HP.COM> <38564@bbn.COM> <2292@solo11.cs.vu.nl>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!agate!bionet!ig!arizona!rupley
From: rupley@arizona.edu (John Rupley)
Newsgroups: comp.editors,comp.unix.questions
Subject: Re: Re^2: SED Question
Summary: need restart loop
Keywords: sed, improvement, fix
Message-ID: <10244@megaron.arizona.edu>
Date: 14 Apr 89 02:14:07 GMT
References: <2360001@hpcuhc.HP.COM> <38564@bbn.COM> <2292@solo11.cs.vu.nl>
Organization: U of Arizona CS Dept, Tucson
Lines: 65