sed question

Peter Chubb,-x27,6982322,3982735 peterc at suite.sw.oz.au.sw.oz.au
Fri May 17 14:30:40 AEST 1991


>From article <1991May16.043510.16184 at umbc3.umbc.edu>, by rouben at math16.math.umbc.edu (Rouben Rostamian):
> In article <3880 at wb3ffv.ampr.org> wmark at wb3ffv.ampr.org (Mark Winsor) writes:
>>I know that 
>>
>>sed -n '/PATTERN1/,/PATTERN2/p' filename
>>
>>will print everything between pattern 1 & 2, but what if I only want the
>>first occurence of these patterns in the file? I know I can pipe the above
>>statement to sed '/PATTERN2/q' but there has got to be a way to do this
>>in one sed process. Thanks.
> 
> Here it is -- one sed process:
	(sed script using branches elided)

Why not use multiple -e options?  That's a little simpler than using
branches and labels. 

Thus:
	sed -n -e '/PATTERN1/,/PATTERN2/p' -e '/PATTERN2/,$d' filename


			Regards,

				- Peter Chubb

Softway Pty Ltd, P.O. Box 305, Strawberry Hills, NSW 2012, AUSTRALIA
Phone: +61 2 698 2322;       Fax: +61 2 699 9174;     Telex: AA27987
Internet: peterc at softway.oz.au	   UUCP: ...!uunet!softway.oz!peterc



More information about the Comp.unix.shell mailing list