[plug] Limits of grep?

Subba Rao subb3 at attglobal.net
Sat Sep 30 13:41:01 WST 2000


On  0, Bill Cullen <billc at iinet.net.au> 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"
> > 
> > What is the file argument limit for grep? I guess you need the grep source
> > for this. I did not find any information in the man page.
> > 
> > Are there any other recommended tools to search through such large list of
> > files?
> 
> This isn't a grep error, it's actually a shell error message.
> You can get the same error by cd'ing to the directory and then
> typing
> 
>     ls *
> 
> It's very important to understand that (unlike M$-DOS) the shell
> exands wildcards and variables and then passes the expanded list
> on to the program. For example, if I have a directory with the
> files fred1 and fred2 and then I enter the command
> 
>     ls fred*
> 
> the ls program will actually receive two command line parameters:
> fred1 and fred2. Similarly, if I have an environment variable
> VAR1=fred and then do the command
> 
>     wc $VAR1
> 
> then the wc program will actually get passed the command line
> parameter fred rather than $VAR1. 
> 
> There are several ways to get around the argument too long error:
> 
>   1. use the for statement as someone has suggested
>   2. use the find statement as someone else has suggested
>   3. try to break the list of files up a bit (ie a*)
>   4. use the xargs command (which I think might be the best 
>      solution in this case). ie. to list the names of all the
>      files with the string "I'm a teapot"
>    
>          ls | xargs grep -l "I'm a teapot"
> 
> I'd take a look in my "UNIX Power Tools" book and be more specific
> but unfortunately it's at work.
>  
> Good Luck,
> 
> Bill Cullen
> 

Thanks Bill, for replying. I tried the following solution and t works very fast.

find <path> -print | xargs -n 500 grep <pattern>

Thanks to everyone who replied with some solution!

-- 

Subba Rao
subb3 at attglobal.net
http://pws.prserv.net/truemax/



More information about the plug mailing list