A little help with SED please - cla
Paul Lew
lew at gsg.UUCP
Fri Apr 22 07:56:17 AEST 1988
> I need an sed line (or some gory pipeline) to extract the data between
> ^^^^^^^^^^^^^^^^^^^^^^
> BEGIN and END.
>
> I should have added the following:
>
> >I have a text file of this form:
> [... junk ...]
> > BEGIN
> > 1
> > 2
> > 3
> > END
> [... junk ...]
> > BEGIN
> > 4
> > 5
> > 6
> > END
> [... junk ...]
>
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
I dont like the awk script because I have to THINK about the logic, the
2nd command is easier to use but it only handle the 1st occurrence and
slower. The sed script is tricky to remember too, it should be the fastest
among the 3 choices listed above.
--
Paul Lew {oliveb,harvard,decvax}!gsg!lew (UUCP)
General Systems Group, 5 Manor Parkway, Salem, NH 03079 (603) 893-1000
More information about the Comp.unix.wizards
mailing list