This is the mail archive of the
cygwin
mailing list for the Cygwin project.
Re: Why doesn't "find .|grep aword" work?
- From: "Mark J. Reed" <markjreed at gmail dot com>
- To: cygwin at cygwin dot com
- Date: Mon, 6 Jul 2009 13:17:14 -0400
- Subject: Re: Why doesn't "find .|grep aword" work?
- References: <24359078.post@talk.nabble.com>
On Mon, Jul 6, 2009 at 1:13 PM, km4hr wrote:
>
> Do pipes work in cygwin in the usual way?
Pipes on Cygwin work in the usual way. You seem to misunderstand how
find and grep work.
> Why doesn't the following command works on HP Unix? Why not cygwin?
> I get no output from this command even though I'm sure the word "hello" is
> in some files.
>
> find .|grep "hello"
That will look for files whose *name* contains "hello". The output of
'find" is a list of filenames. You then run grep on that list looking
for the string "hello".
If you want to instead run grep "hello" on all the files found by
find, then the simplest change to your command is to introduce the
xargs ("transpose arguments") utility, like this:
find . | xargs grep hello
However, that will fail on files with strange names, and give you
errors about trying to grep directories, so what you really want is
this:
find . -type f -print0 | xargs -0 grep hello
None of this is Cygwin-specific. It's just the way find and grep
work, on all UNIXlike systems.
--
Mark J. Reed <markjreed@gmail.com>
--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple