[NTLUG:Discuss] in a world where grep doesn't have the -m (match) option..
Steve Baker
steve at sjbaker.org
Tue Mar 25 22:18:32 CDT 2008
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!
>
As soon as 'head' has read enough input to satisfy your demand to
display one line, it'll exit. That causes a 'broken' link on the output
of 'grep' which will crap out and die as a result. So the only wasted
time is the time grep spends searching onwards while head displays your
line of data.
Of course you could also grab the sourcecode for GNU grep and install it
on whatever pathetic machine you're using that doesn't have '-m'...but
that's another story!
More information about the Discuss
mailing list