views:

677

answers:

2

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
+7  A: 

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.

Brian Agnew
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
CheeseConQueso
It simply causes all errors to be sent to /dev/null, where they will be ignored.
Matthew Flaschen
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
Brian Agnew
find . 2>/dev/null | awk '!/((\.jpeg)|(\.jpg)|(\.png))$/ {print $0;}' | xargs grep "B206" 2>/dev/null
CheeseConQueso
works good, thanks
CheeseConQueso
A: 

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

travellingfelix