Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!wuarchive!uunet!lll-winken!aunro!atha!mips!ultra!marc From: marc@mercutio.ultra.com (Marc Kwiatkowski {Host Software-AIX}) Newsgroups: comp.unix.shell Subject: sed man page error (Was "Re: sed question") Message-ID: <1991May17.211650.2025@ultra.com> Date: 17 May 91 21:16:50 GMT References: <3880@wb3ffv.ampr.org> <1991May16.085837.1368@ultra.com> Sender: marc@ultra.com (Marc Kwiatkowski {Host Software-AIX}) Distribution: comp Organization: Ultra Network Technologies Lines: 85 In-Reply-To: marc@mercutio.ultra.com's message of Thu, 16 May 91 08:58:37 GMT In article <1991May16.085837.1368@ultra.com> marc@mercutio.ultra.com (Marc Kwiatkowski {Host Software-AIX}) 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. > sed -n ' > /pattern00/ { > :lbl00 > n > /pattern01/ { > q > } > p > b lbl00 > }' Someone pointed out that the according to the documentation, this solution shouldn't work. Of course it does work, so I thought I'd point out the sed documentation error that exists in every sed man page I've ever seen. From 4.3BSD URM sed man page: n Copy the pattern space to the standard output. Replace the pattern space with the next line of input. It should read: n Copy the pattern space to the standard output unless "-n" flag has been specified. Replace the pattern space with the next line of input. It is surprising that this documentation error has existed for so long, and has been reproduced so faithfully by numerous Unices. It makes one suspect that the additional features of sed aren't used by many. If you'll allow me to get on my soapbox, I'd like to campaign for sed. sed's syntax is somewhat obtuse, but it takes far less time to load than awk. Since most of shell-script execution time is spent creating pipes and filter-processes, this can be a real win. Context sensitive parsing is beyond the scope of sed - well not really, but it starts to get very ugly - however, I'd guess that the vast majority of filters written in awk are regular and could easily be recast in sed. perl is probably better than awk or sed for regular filters, since it provides both a rich set regular expression and flow control commands, and it avoids the overhead of pipe and process creation. The bourne shell is still the lingua franca of shell scripts, so until the time that perl become ubiquitous, I think sed should be the filter of first resort. I think a close, but gimletted, reading of the sed man page and a few experimental sed scripts will convince the reader that more is possible in sed than previously thought possible; especially when one makes use of the hold space. My two A cents -- ------------------------------------------------------------------ Marc P. Kwiatkowski Ultra Network Technologies Internet: marc@ultra.com 101 Daggett Drive uucp: ...!ames!ultra!marc San Jose, CA 95134 USA telephone: 408 922 0100 x249 Ignore the following signature. -- ------------------------------------------------------------------ Marc P. Kwiatkowski Ultra Network Technologies Internet: marc@ultra.com 101 Daggett Drive uucp: ...!ames!ultra!marc San Jose, CA 95134 USA