Re^2: SED Question

John Rupley rupley at arizona.edu
Fri Apr 14 12:14:07 AEST 1989


In article <2292 at solo11.cs.vu.nl>, maart at cs.vu.nl (Maarten Litmaath) writes:
> jgrace at 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 at megaron.arizona.edu



More information about the Comp.unix.questions mailing list