bug-bash
[Top][All Lists]
Advanced

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

Re: grep remove "no such file or directory"


From: Greg Wooledge
Subject: Re: grep remove "no such file or directory"
Date: Wed, 6 May 2009 10:22:04 -0400
User-agent: Mutt/1.4.2.2i

On Wed, May 06, 2009 at 04:03:51PM +0200, Roman Rakus wrote:
> On 05/06/2009 02:14 PM, cseguino wrote:

> >     $ find . | xargs grep -v "No such file or directory" | grep "StateRB"
> >     grep:
> >./Tiger/codebase/netmarkets/jsp/ext/eurocopter/tiger/change/.svn/text-base/Copy:
> >No such file or directory
> >     grep: of: No such file or directory
[...]

There are several problems with your command.

What you have actually written here is "Traverse the list of all the files
and directories underneath this point, opening each file and looking
for all the lines that do not contain the string 'No such file or directory',
and out of all those lines, look for ones that contain the string 'StateRB'."

But that won't actually work as written because xargs splits your filenames
on whitespace (and quotes, if Cygwin allows you to have filenames with
quotes in them).  This is why you got the result you got -- the "of" being
treated as a separate file by xargs, instead of ".../text-base/Copy of..."
being a single file.

> >I would like not to display the "No such file or directory" output. Can
> >anyone help me ?

It's not clear what you actually DO want.

> This message is error message and error messages are sent to stderr. 
> Usualy stderr are same as stdout. But you can redirect stderr with `2>'.
> find . 2>/dev/null
> This will not display any error messages from `find .'

As Ramon points out, if what you're actually trying to do isn't "open
up each file and look for lines not containing the string 'No such file
or directory'" but rather "if find encounters an error opening a
directory, don't show me find's errors", then you want this instead:

find . 2>/dev/null

But it's not at all clear to me where the "StateRB" part applies.

If your actual problem is "Find all the files containing the string
StateRB, and suppress all error messages", then use this:

find . -type f -exec grep -l StateRB {} \; 2>/dev/null

Or if your grep supports it:

grep -l -r StateRB . 2>/dev/null

(grep -r is not a standard feature, so you can't assume it will work; but
it works on GNU find, which I suspect is what Cygwin has.)




reply via email to

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