Path: utzoo!mnetor!uunet!husc6!yale!decvax!gsg!lew From: lew@gsg.UUCP (Paul Lew) Newsgroups: comp.unix.wizards Subject: Re: A little help with SED please - cla Message-ID: <146@gsg.UUCP> Date: 21 Apr 88 21:56:17 GMT References: <142700030@occrsh.ATT.COM> Organization: General Systems Group, Inc., Salem, NH Lines: 41 > 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