[NTLUG:Discuss] in a world where grep doesn't have the -m (match) option..
Robert Citek
robert.citek at gmail.com
Tue Mar 25 21:52:41 CDT 2008
On Tue, Mar 25, 2008 at 5:03 PM, Chris Cox <cjcox at acm.org> wrote:
> Richard wrote:
> > Chris Cox wrote:
> >> Richard wrote:
> >>
> >>> ..how would one go about stopping a grep after the first match? <snippage>
> >> <snippage>
> >>
> >> grep 'whatever' file | head -1
> >> (that's a minus one)
> >>
> > AH YES!! That's brilliant! It would cause the search to continue..but
> > WOULD get the job done. Thanks Chris!
> >
>
> Shouldn't continue. Should terminate after a full buffer containing
> the matched string goes to the head command.
For example:
$ time -p yes hello | grep hello | head -10000000 | wc -l
10000000
real 2.04
user 2.40
sys 0.30
$ time -p yes hello | grep hello | head -1 | wc -l
1
real 0.01
user 0.01
sys 0.00
$ time -p yes hello | grep -m 1 hello | wc -l
1
real 0.00
user 0.00
sys 0.00
Regards,
- Robert
More information about the Discuss
mailing list