Path: utzoo!mnetor!uunet!lll-winken!lll-lcc!ames!umd5!mimsy!chris From: chris@mimsy.UUCP (Chris Torek) Newsgroups: comp.unix.wizards Subject: Re: A little help with SED please - cla Message-ID: <11190@mimsy.UUCP> Date: 23 Apr 88 12:35:06 GMT References: <5490@sigi.Colorado.EDU> <142700030@occrsh.ATT.COM> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 29 In article <142700030@occrsh.ATT.COM> rjd@occrsh.ATT.COM writes: [bits, words, and paragraphs deleted] -BEGIN { - prnt=0 - bgn=0 -} - -/BEGIN/ && $0 == "BEGIN" {prnt=1;bgn=1} -/END/ && $0 == "END" {prnt=0} - -NF > 0 { -if( prnt == 1 && bgn != 1) - print $0 -bgn=0 -} The variable `bgn' can be eliminated by using the `next' construct: /^BEGIN$/ { prt = 1; next } # tweak R.E. as appropriate /^END$/ { prt = 0 } NF > 0 { if (prt) print } Voila!, three lines. This does depend on uninitialised variables being numerically zero, which is true in awk, but perhaps considered bad style. If so, add a fourth line: BEGIN { prt = 0 } -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163) Domain: chris@mimsy.umd.edu Path: uunet!mimsy!chris