PDA

View Full Version : [SOLVED] How do I Sed the output of Find?



kliq
October 16th, 2011, 09:42 PM
Hello

I wanted to filter the output of Find containing lines such as:


find: ‘/proc/4689/fd’: Permission denied
by doing:


find / -name xli* -print | sed -n '/denied/d; p'
but I still get all the "Permission denied" lines.
What am I doing wrong?

Vaphell
October 16th, 2011, 10:07 PM
try


find / -name xli* 2>&1 | sed -n '/denied/d; p'
these are messages sent to stderr, while pipe catches stdout. This construct channels error messages to stdout

alternatively grep instead of sed

find / 2>&1 | grep -v denied

even better to redirect stderr to /dev/null with no piping at all

find / -name xli* 2>/dev/null

papibe
October 16th, 2011, 10:54 PM
Besides Vaphell's good advices, I just wanted to point out that the name expression will be affected by shell globbing. My guess is that you don't want that, and you are looking for files and directories that match the intact expression.

In order to do that use:

'xli*' or this

xli\*
Regards.

kliq
October 17th, 2011, 10:45 AM
Thank you Vaphell and Papibe for your help.