Xref: utzoo comp.unix.wizards:8906 comp.unix.questions:7301 Path: utzoo!attcan!uunet!yale!cmcl2!phri!roy From: roy@phri.UUCP (Roy Smith) Newsgroups: comp.unix.wizards,comp.unix.questions Subject: Re: grep replacement Message-ID: <3324@phri.UUCP> Date: 28 May 88 13:59:20 GMT References: <4524@vdsvax.steinmetz.ge.com> <1036@cfa.cfa.harvard.EDU> Reply-To: roy@phri.UUCP (Roy Smith) Organization: Public Health Research Inst. (NY, NY) Lines: 25 wyatt@cfa.harvard.EDU (Bill Wyatt) writes: [as a way to get just the first occurance of pattern] > grep '(your_pattern_here)' | head -1 Yes, it'll certainly work, but I think it bypasses the original intention; to save CPU time. If I had a 1000 line file with pattern on line 7, I want grep to read the first 7 lines, print out line 7, and exit. grep|head, on the other hand, will read and search all 1000 lines of the file; it won't exit (with a EPIPE) until it writes another line to stdout and finds that head has already exited. In fact, if grep block-buffers its output, it may never do more than a single write(2) and never notice that head has exited. Anyway, I agree with the "find first match" flag being a good idea. It would certainly speed up things like grep "^Subject: " /usr/spool/news/comp/sources/unix/* where I know that the pattern is going to be matched in the first few lines and don't want to bother searching the rest of the multi-killoline file. -- Roy Smith, System Administrator Public Health Research Institute 455 First Avenue, New York, NY 10016 {allegra,philabs,cmcl2,rutgers}!phri!roy -or- phri!roy@uunet.uu.net