A little help with SED please - cla

Chris Torek chris at mimsy.UUCP
Sat Apr 23 22:35:06 AEST 1988


In article <142700030 at occrsh.ATT.COM> rjd at 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 at mimsy.umd.edu	Path:	uunet!mimsy!chris



More information about the Comp.unix.wizards mailing list