grep replacement

T. Andrew Crump andyc at omepd
Wed Jun 1 02:03:32 AEST 1988


In article <1036 at cfa.cfa.harvard.EDU> wyatt at cfa.harvard.EDU (Bill Wyatt) writes:

>> 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

Yes, but it forces grep to search a whole file, when what you may have wanted
was at the beginning.  This is inefficient if the "file" is large.

A more general version of this request would be a parameter that would restrict
grep to n or less occurrences, maybe 'grep -N #'.

-- Andy Crump



More information about the Comp.unix.wizards mailing list