Xref: utzoo comp.unix.wizards:9228 comp.unix.questions:7509 Path: utzoo!attcan!uunet!lll-winken!lll-tis!ames!mailrus!tut.cis.ohio-state.edu!bloom-beacon!mcgill-vision!mouse From: mouse@mcgill-vision.UUCP (der Mouse) Newsgroups: comp.unix.wizards,comp.unix.questions Subject: Re: grep replacement (SIGPIPE) Message-ID: <1151@mcgill-vision.UUCP> Date: 10 Jun 88 09:39:46 GMT References: <7882@alice.UUCP> <5630@umn-cs.cs.umn.edu> <6866@elroy.Jpl.Nasa.Gov> <5007@sdcsvax.UCSD.EDU> Organization: McGill University, Montreal Lines: 27 In article <5007@sdcsvax.UCSD.EDU>, hutch@net1.ucsd.edu (Jim Hutchison) writes: > 4537@vdsvax.steinmetz.ge.com, barnett@vdsvax.steinmetz.ge.com (Bruce G. Barnett) >> In <1036@cfa.cfa.harvard.EDU> wyatt@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@mcgill-vision.uucp arpa: mouse@larry.mcrcim.mcgill.edu