Register
It is currently Fri Oct 31, 2014 4:11 pm

grep remove "no such file or directory"


All times are UTC - 6 hours


Post new topic Reply to topic  [ 7 posts ] 
Author Message
 PostPosted: Tue May 05, 2009 6:52 am   

Joined: Tue May 05, 2009 6:49 am
Posts: 4
Hello,

I'm executing the following command using cygwin :
Code:
$ 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
grep: createLink.jsp.svn-base: No such file or directory
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
grep: relatedECP.jsp.svn-base: No such file or directory
grep: ./Tiger/codebase/netmarkets/jsp/ext/eurocopter/tiger/change/Copy: No such file or directory
grep: of: No such file or directory
grep: createLink.jsp: No such file or directory
grep: ./Tiger/codebase/netmarkets/jsp/ext/eurocopter/tiger/change/Copy: No such file or directory
grep: of: No such file or directory


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

Cheers,

Christophe


Top
 Profile  
 PostPosted: Tue May 05, 2009 7:23 am   
Moderator
User avatar

Joined: Wed May 03, 2006 2:05 pm
Posts: 242
There's probably a more elegant solution, but try redirecting the stderr from the find command to stdout, so that your grep -v will catch those messages:

Code:
find . 2>&1 | xargs grep -v "No such file or directory" | grep "StateRB"


Top
 Profile YIM  
 PostPosted: Wed May 06, 2009 12:59 am   

Joined: Tue May 05, 2009 6:49 am
Posts: 4
It still doesn't work :
Code:
$ find . 2>&1 | 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
grep: createLink.jsp.svn-base: No such file or directory
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
grep: relatedECP.jsp.svn-base: No such file or directory
grep: ./Tiger/codebase/netmarkets/jsp/ext/eurocopter/tiger/change/Copy: No such file or directory
grep: of: No such file or directory


Cheers,

Christophe


Top
 Profile  
 PostPosted: Thu May 07, 2009 8:52 am   
Moderator
User avatar

Joined: Thu Oct 11, 2007 7:12 am
Posts: 229
Location: London - UK
your use of xargs is the issue, the output from the find command is supplied as an argument to grep not as the input;

this will check each file 'hello' and 'there' for the lines missing the content 'wibble'
Code:
echo hello there | xargs grep -v wibble


where as this will check what the echo outputs and remove lines containing 'wibble'
Code:
echo hello there | grep -v wibble


what I suspect you actually need (and this is a guess);
Code:
find . 2>/dev/null | xargs grep "StateRB"


or maybe;
Code:
find . 2>&1 | grep -v "No such file or directory" | xargs grep "StateRB"


Top
 Profile  
 PostPosted: Fri Feb 19, 2010 7:37 am   

Joined: Fri Feb 19, 2010 7:35 am
Posts: 1
Greetings,

This does it...

find . |xargs grep -i val 2>/dev/null | grep -i tracy

Note that the error is from the grep not from the find...
curious but it works.

Regards,

Flint


Top
 Profile  
 PostPosted: Mon May 09, 2011 7:33 am   

Joined: Mon May 09, 2011 7:31 am
Posts: 1
Don't forget that grep has the -s option to deal with this as well.


Top
 Profile  
 PostPosted: Wed May 11, 2011 9:28 am   
Site Admin
User avatar

Joined: Sun May 15, 2005 9:36 pm
Posts: 669
Location: Des Moines, Iowa
I'd have to agree with spoonyfork ... use the -s option.

Code:
    -s, --no-messages
              Suppress error messages about nonexistent or unreadable  files.   Portability  note:  unlike  GNU  grep,  7th
              Edition Unix grep did not conform to POSIX, because it lacked -q and its -s option behaved like GNU grep's -q
              option.  USG-style grep also lacked -q but its -s option behaved  like  GNU  grep.   Portable  shell  scripts
              should  avoid  both  -q  and  -s  and should redirect standard and error output to /dev/null instead.  (-s is
              specified by POSIX.)


Top
 Profile WWW  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Watael and 8 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP