maart@cs.vu.nl (Maarten Litmaath) (04/13/89)
jgrace@bbn.com (Joe Grace) writes: \... \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 -n ' /^PROMPT>$/{ $p h n H /^>$/{ $b eof n /^<$/b H } : eof g } p ' -- "If it isn't aesthetically pleasing, |Maarten Litmaath @ VU Amsterdam: it's probably wrong." (jim@bilpin). |maart@cs.vu.nl, mcvax!botter!maart
leo@philmds.UUCP (Leo de Wit) (04/14/89)
In article <2292@solo11.cs.vu.nl> maart@cs.vu.nl (Maarten Litmaath) writes: [] |My first sed attempt can easily be fixed to handle partial matches at EOF |properly: | |sed -n ' | /^PROMPT>$/{ | $p | h | n | H | /^>$/{ | $b eof | n | /^<$/b | H | } | : eof | g | } | p |' I think you'll need a third attempt 8-). It still doesn't handle correct a series of lines like PROMPT> PROMPT> > < or one like PROMPT> > PROMPT> > < Alternative: sed -n ' : start $p $q N /^PROMPT>\n>\n<$/d /\n[^\n]*\n/{ P D } b start' Leo.
rupley@arizona.edu (John Rupley) (04/14/89)
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
danny@itm.UUCP (Danny) (04/14/89)
Uh, Why not use the sed comma operator? Like: sed '/^PROMPT>/,/^>/d' file I got the impression that the original poster didn't care WHAT lay between the first and last match lines. Danny -- Daniel S. Cox (seismo!gatech!itm!danny)
uucibg@sw1e.UUCP (3929]) (04/15/89)
In article <1003@philmds.UUCP> leo@philmds.UUCP (Leo de Wit) writes:
=I think you'll need a third attempt 8-). It still doesn't handle correct
=a series of lines like
=
= PROMPT>
= PROMPT>
= >
= <
=
=or one like
=
= PROMPT>
= >
= PROMPT>
= >
= <
=
=Alternative:
=
=sed -n '
=: start
=$p
=$q
=N
=/^PROMPT>\n>\n<$/d
=/\n[^\n]*\n/{
= P
= D
=}
=b start'
=
= Leo.
I think I may have missed a posting or two on this topic. Could someone
please tell me why the following does not handle the problem:
cat myfile | sed -e '/^PROMPT>$/,/^<$/d'
Many thanks,
Brian R. Gilstrap Southwestern Bell Telephone
One Bell Center Rm 17-G-4 ...!ames!killer!texbell!sw1e!uucibg
St. Louis, MO 63101 ...!bellcore!texbell!sw1e!uucibg
(314) 235-3929
#include <std_disclaimers.h>