A little help with SED please

David Goodenough dg at lakart.UUCP
Thu May 5 00:41:54 AEST 1988


>From article <762 at pttesac.UUCP>, by robert at pttesac.UUCP (Robert Rodriguez):
> In article <1988Apr26.011145.27914 at lsuc.uucp> dave at lsuc.UUCP (David Sherman) writes:
>>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.
>>[more stuff on "awk" deleted]
> 
> I'm surprised nobody mentioned csplit.  It's perfect for this stuff,
> as the man page says, csplit is a context splitter.
> 
> csplit -s -k foo /BEGIN/+1 /END/-1

May work, but csplit is nowhere to be found on our system (BSD 4.3).

Seriously though, the following awk script does nicely, although it may
need a bit of work if there is more than one field on a line:

--- snip snip snippety snip --- snip snip snippety snip ---
 {
    if ($1 == "BEGIN")
     {
	state = 1
     }
    else if ($1 == "END")
     {
	state = 0
     }
    else if (state == 1)
     {
	print $1
     }
 }
--- snip snip snippety snip --- snip snip snippety snip ---
-- 
	dg at lakart.UUCP - David Goodenough		+---+
							| +-+-+
	....... !harvard!adelie!cfisun!lakart!dg	+-+-+ |
						  	  +---+



More information about the Comp.unix.questions mailing list