[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Limits of grep?
Herouth Maoz <herouth@netvision.net.il> writes:
> Gavrie Philipson wrote:
> >
> > Subba Rao wrote:
> > >
> > > I have a directory of 10000+ text files and would like to search for
> > > some strings in these files. When I tried using "grep" command with an
> > > asterisk, I get the error message somthing to the effect,
> > >
> > > "File argument list too long"
> > >
> >
> > Besides Shachar's answer about using 'find', you could also use the
> > 'xargs' command. In this case, 'ls | xargs grep <pattern>' should do the
> > trick.
>
> And it would also do what was originally intended. Using 'find' will go
> recursively into subdirectories. If one was able to use grep *, no recursion
> would be performed.
Some comments that were omitted in the thread so far.
1) You can use find without descending into subdirectories (perusing
the documentation is left as an exercise to the reader).
2) I believe that find | xargs (or ls | xargs) has an advantage over
Shachar's suggestion in that the latter will spawn 10000+ grep
processes.
3) An additional benefit of xargs will be that grep will show you the
file name for each match, while in Shachar's variant each grep will
be run on just one file and the file name will not be there by
default (yes, you can use --with-filename option, a.k.a. -H).
--
Oleg Goldshmidt <ogoldsh@NOSPAM.netvision.net.il>
"... We work by wit, and not by witchcraft;
And wit depends on dilatory time." [Shakespeare]
=================================================================
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