bug-gnu-utils
[Top][All Lists]
Advanced

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

Re: GREP 2.4.2 - 2.5.1a Recursion Problem


From: Bob Proulx
Subject: Re: GREP 2.4.2 - 2.5.1a Recursion Problem
Date: Sun, 5 Aug 2007 00:02:19 -0600
User-agent: Mutt/1.5.9i

Alan C wrote:
> The program will not recurse when target files matching the file spec do not
> exist in the top folder.
> ...
> D:\greptest>grep -ri "testtext" *.txt
> testtext
> ...
> D:\greptest>grep -ri "testtext" *.txt
> grep: *.txt: No such file or directory

Because *.txt will never match a directory there is nothing for grep
to recurse down.  The -r option only applies to command line arguments
that happen to be directories.

Of course some people do like the recursion added to grep itself but I
am not one of them.  It is much better to use find for this and then
the technique will apply not only to grep but to all of the
utilities.  This is more in keeping with the Unix philosophy of using
small and simple programs to build up more complicated processes.

  find . -name "*.txt" -print0 | xargs -r0 grep -i "testtext"

Or if you have a newer 'find' with the "{} +" option this is more
efficient.

  find . -name "*.txt" -exec grep -i "testtext" {} +

> Also, for command line utilities (e.g. 2.5.1a, grep.exe, in GNUWin32) I
> recommend that the compiled version be statically built without dependency
> on DLL's. This makes it more easily transportable between systems (e.g. on a
> USBKey).

For that request you would need to talk to those who compiled your
version of grep.  In other words, you should ask the GNUWin32 folks
for that request.

Bob




reply via email to

[Prev in Thread] Current Thread [Next in Thread]