[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Limits of grep?



On Wed, Sep 27, 2000, Omer Musaev wrote about "Re: Limits of grep?":
> xargs has flags -n , -l , -s to limit amount od args xargs execs each time.
> Thus, having find . -name "*"  | xargs -n 500  , and assuming that find will return
> 654 file names, xargs will run _twice_, one time with 500 args, second time with 154
> 
> However, more elegant (IMHO) solution is not to use find and xargs at all, but
> instead use :
> 
> ls  | while read file_name ; do grep pattern $filename ; done
> (sh  syntax used )

Yes, but that will run the 'grep' program 654 times, compared to 2 times in
the xargs solution in your example! Forgetting for a moment the small difference
in grep output between one and many files, the problem with your last solution
is that it is much slower because the grep executable is loaded 654 times,
fork is done 654 times, share libraries are linked 654 times, and so on.
On todays computers, with fast CPUs, disks, in-memory disk cache, and fast
fork, this is not bad (but still not good!), but in the good-old-days, the
xargs solution would be significantly more efficient.

So if you need a quick-and-dirty script, use a loop like Omer suggested (but
it contains a small typo - fix it first!) - it's more flexible and general.
But if efficiency is important, the xargs solution wins. If you're looking
for less typing, the xargs solution is shorter too :)

-- 
Nadav Har'El                        |     Wednesday, Sep 27 2000, 27 Elul 5760
nyh@math.technion.ac.il             |-----------------------------------------
Phone: +972-53-245868, ICQ 13349191 |I want to be a human being, not a human
http://nadav.harel.org.il           |doing -- Scatman John

=================================================================
To unsubscribe, send mail to linux-il-request@linux.org.il with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail linux-il-request@linux.org.il