Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!thunder.mcrcim.mcgill.edu!snorkelwacker.mit.edu!usc!rpi!batcomputer!munnari.oz.au!metro!cluster!swift!suite.sw.oz.au!peterc From: peterc@suite.sw.oz.au.sw.oz.au (Peter Chubb,-x27,6982322,3982735) Newsgroups: comp.unix.shell Subject: Re: sed question Message-ID: <1991May17.043040.21660@softway.sw.oz.au> Date: 17 May 91 04:30:40 GMT References: <1991May16.043510.16184@umbc3.umbc.edu> Sender: news@softway.sw.oz.au (Usenet) Organization: Softway Pty Ltd Lines: 28 Originator: peterc@suite.sw.oz.au From article <1991May16.043510.16184@umbc3.umbc.edu>, by rouben@math16.math.umbc.edu (Rouben Rostamian): > In article <3880@wb3ffv.ampr.org> wmark@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@softway.oz.au UUCP: ...!uunet!softway.oz!peterc