sed man page error (Was "Re: sed question")

Marc Kwiatkowski {Host Software-AIX} marc at mercutio.ultra.com
Sat May 18 07:16:50 AEST 1991


In article <1991May16.085837.1368 at ultra.com> marc at 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 at 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 at ultra.com		101 Daggett Drive
	uucp: ...!ames!ultra!marc		San Jose, CA 95134 USA



More information about the Comp.unix.shell mailing list