6

I was given this syntax by user phi

find . | awk '!/((\.jpeg)|(\.jpg)|(\.png))$/ {print 0ドル;}' | xargs grep "B206"

I would like to suppress the output of grep: can't open..... and find: cannot open lines from the results.

sample output to be ignored:

grep: can't open ./cisc/.xdbhist
find: cannot open ./cisc/.ssh
asked Jun 22, 2009 at 19:06

2 Answers 2

12

Have you tried redirecting stderr to /dev/null ?

2>/dev/null

So the above redirects stream no.2 (which is stderr) to /dev/null. That's shell dependent, but the above should work for most. Because find and grep are different processes, you may have to do it for both, or (perhaps) execute in a subshell. e.g.

find ... 2>/dev/null | xargs grep ... 2>/dev/null

Here's a reference to some documentation on bash redirection. Unless you're using csh, this should work for most.

Jonathan Leffler
759k145 gold badges961 silver badges1.3k bronze badges
answered Jun 22, 2009 at 19:09
Sign up to request clarification or add additional context in comments.

4 Comments

im a little hesitant to try it out.... what does this do exactly? it just doesn't seem like it will do what i need, but thats from a 370 talking to a 9,733
It simply causes all errors to be sent to /dev/null, where they will be ignored.
It makes the assumption (which I've not checked, I confess) that your errors above come out on std err. 2>/dev/null will redirect errors to /dev/null (a bin) in the same way that (say) find ... > /tmp/find.results would redirect std out to a file
find . 2>/dev/null | awk '!/((\.jpeg)|(\.jpg)|(\.png))$/ {print 0ドル;}' | xargs grep "B206" 2>/dev/null
9

The option flag grep -s will suppress these messages for the grep command

answered Feb 4, 2010 at 12:30

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.