A little help with SED please - clarifications.

Dave Burton daveb at laidbak.UUCP
Thu Apr 21 00:54:05 AEST 1988


In article <5490 at sigi.Colorado.EDU> murillo at boulder.Colorado.EDU (Rodrigo Murillo) writes:
|I need an sed line (or some gory pipeline) to extract the data between
|BEGIN and END.
|	>I have a text file of this form:
|	    [... junk ...]
|	>   BEGIN
|	>     1
|	>     2
|	>     3
|	>   END
|	    [... junk ...]
|	>   BEGIN
|	>     4
|	>     5
|	>     6
|	>   END
|	    [... junk ...]
|Add to that the fact that the data between BEGIN...END is really not
|plain sequential numbers; it is random text.  Sorry I was not more
|clear.  If you have a SED line to deal with the above, I would love to 
|see it.  Thanks.

Awk would be the tool of choice here. Your basic problem is that you
have state in your text file (in,out), and the state changes only on
subsequent lines. It is difficult (probably not impossible) to write
a sed script, though an awk script is trivial. Try:

awk '
/^BEGIN$/ { state = "in";  next }
/^END$/   { state = "out"; next }
{ if (state == "in") print $0 }
' < yourfile

-- 
--------------------"Well, it looked good when I wrote it"---------------------
 Verbal: Dave Burton                        Net: ...!ihnp4!laidbak!daveb
 V-MAIL: (312) 505-9100 x325            USSnail: 1901 N. Naper Blvd.
#include <disclaimer.h>                          Naperville, IL  60540



More information about the Comp.unix.wizards mailing list