grep replacement (SIGPIPE)

der Mouse mouse at mcgill-vision.UUCP
Fri Jun 10 19:39:46 AEST 1988


In article <5007 at sdcsvax.UCSD.EDU>, hutch at net1.ucsd.edu (Jim Hutchison) writes:
> 4537 at vdsvax.steinmetz.ge.com, barnett at vdsvax.steinmetz.ge.com (Bruce G. Barnett)
>> In <1036 at cfa.cfa.harvard.EDU> wyatt at cfa.harvard.EDU (Bill Wyatt) writes:
[attribution(s) lost]
>>>> There have been times when I wanted a grep that would print out
>>>> the first occurrence and then stop.
>>> grep '(your_pattern_here)' | head -1
>> Have you ever waited for a computer?  There are times when I want
>> the first occurrence of a pattern without reading the [whole file].

> grep pattern file1 ... fileN | head -1

> This should send grep a SIGPIPE as soon as the first line of output
> trickles through the pipe.

No.  It should not send the SIGPIPE until grep writes the second line.
And because grep is likely to use stdio for its output, nothing at all
may be written to the pipe until grep has 1K or 2K or whatever size its
stdio uses for the output buffer.  This may be an enormous waste of
time, both cpu and real.

Besides which, it's wrong.  It prints just the first match, whereas
what's wanted is the first match *from each file*.

					der Mouse

			uucp: mouse at mcgill-vision.uucp
			arpa: mouse at larry.mcrcim.mcgill.edu



More information about the Comp.unix.questions mailing list