> -----Original Message-----
> From: Fergal Daly [mailto:fergal at esatclear.ie]
> Sent: 27 September 2000 22:23
> To: Paul Kelly; Subba Rao
> Cc: Irish Linux Users
>> At 12:00 26/09/00, Paul Kelly 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...
> >
> >That's a shell issue as much as grep. Try find . -print | xargs grep
> >"pattern"
>> This will go wrong on any file that has a space or a shell
> meta character and may even end abruptly. To avoid this use
>> find . -print0 | xargs -0 grep "pattern"
>> find will output the filenames in null separated format and
> xargs will expect them like that,
>> Fergal
I find the following construction more general,
in dealing with spaces and tabs in filenames.
This would allow you to pass the output to
something other than xargs, for e.g. to sort
files by size you could do:
find . -type f -printf "%p\0%s\n" | # %p = filename(with spaces) followed
tr ' \t\0' '\0\1 ' | #remove spaces, tabs in file names
sort +1n +0 | #sort by filesize & then by filename
tr '\0\1' ' \t' #reset any space & tabs in filenames
I find the -printf option to find really useful.
Padraig.
Maintained by the ILUG website team. The aim of Linux.ie is to
support and help commercial and private users of Linux in Ireland. You can
display ILUG news in your own webpages, read backend
information to find out how. Networking services kindly provided by HEAnet, server kindly donated by
Dell. Linux is a trademark of Linus Torvalds,
used with permission. No penguins were harmed in the production or maintenance
of this highly praised website. Looking for the
Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!