A little help with SED please - cla

Mark Wallen wallen at sdics.ucsd.EDU
Fri Apr 22 17:20:50 AEST 1988


In article <146 at gsg.UUCP> lew at gsg.UUCP (Paul Lew) writes:
>
> > I need an sed line (or some gory pipeline) to extract the data between
> >                      ^^^^^^^^^^^^^^^^^^^^^^
> > BEGIN and END.
> > 
[Elided--mrw]
>It is very simple to do if the lines contain BEGIN or END should be
>included:
>
>   (1) awk '/BEGIN/,/END/' filename		
>
>It is a bit tricker if you want to exclude BEGIN, END lines:
>
>   (1) awk '/END/ {p=0} p==1 {print} /BEGIN/ {p=1}' filename	or
>   (2) echo '/BEGIN/+1,/END/-1p' | ex - filename		or
>   (3) sed -n '/BEGIN/,/END/{/BEGIN/d;/END/d;p;}' filename
[Elided--mrw]

Wither have the 'ed' hackers of yore gone?  I suppose they're
all 'ex' hackers now :-).  If you change (2) to
echo 'g/BEGIN/.+1,/END/-1p' | ex - filename
(or ed instead of ex), you'll get all data between BEGIN,END
pairs EXCEPT when there is no data.  I.e.,
	BEGIN
	END

Both editors abort on this case (ed with the wonderfully
informative "?" message; thank zeus that some things haven't
changed :-)

Mark R. Wallen
UC San Diego

mwallen at ucsd.edu



More information about the Comp.unix.wizards mailing list