Path: utzoo!mnetor!uunet!lll-winken!lll-tis!ames!ucsd!sdics!wallen From: wallen@sdics.ucsd.EDU (Mark Wallen) Newsgroups: comp.unix.wizards Subject: Re: A little help with SED please - cla Message-ID: <495@sdics.ucsd.EDU> Date: 22 Apr 88 07:20:50 GMT References: <142700030@occrsh.ATT.COM> <146@gsg.UUCP> Organization: Institute for Cognitive Science, UC San Diego Lines: 35 Summary: an adjustment to the echo '' | ex - version In article <146@gsg.UUCP> lew@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@ucsd.edu