[comp.unix.wizards] A little help with SED please - clarifications.

murillo@sigi.Colorado.EDU (Rodrigo Murillo) (04/19/88)

Gentle readers:

A clarifiction to my previous posting.

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 ...]

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.
-- 
_______________________________________________________________________________
 Rodrigo Murillo, University of Colorado - Boulder  (303) 761-0410 
 murillo@boulder.colorado.edu | ..{ncar|nbires}!boulder!murillo
 ( Machines have less problems.  I'd like to be a machine. -- Andy Warhol )

daveb@laidbak.UUCP (Dave Burton) (04/20/88)

In article <5490@sigi.Colorado.EDU> murillo@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