Mail Archives: cygwin/2002/07/16/20:12:58
On Tue, Jul 16, 2002 at 06:31:53PM -0500, Dan Higgins wrote:
> Greetings,
>
> If I want to recursively find all files that contain some text, I use, for
> example:
>
> find . -name '*.java' | while read l; do grep 'Copyright' "$l" && echo "$l";
> done
>
> The output from this pipeline is inconsistent. Mostly I see bogus pathnames
> that should not be there, or missing pathnames that should be there, or
> duplicate lines from the grep, that sometimes even wind up overlapped by the
> command prompt upon completion.
>
> 1. Don't suggest another syntax, unless it can handle paths with
> spaces in it.
Well, the following will handle spaces just fine:
$ find . -name '*.java' -print0 | xargs -0 grep -l 'Copyright'
This will actually be faster, since it will greatly minimize the
number of fork/exec pairs (your command line does a grep for *each*
file, whereas the find / xargs pipeline will do a *single* grep for
a bunch of files.) BTW, this isn't really a Cygwin-specific question,
rather a somewhat common Unix question.
--
Dario Alcocer -- Sr. Software Developer, Helix Digital Inc.
alcocer AT helixdigital DOT com -- http://www.helixdigital.com
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Bug reporting: http://cygwin.com/bugs.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
- Raw text -