Submitted by Pronco on Wed, 02/02/2005 - 07:05.
( categories: Miscellaneous )

How do I pipe STDERR?

I do not want to redirect STDERR or STDOUT to a file. I want to 'pipe' std error through a filter (grep)

How do I grep the STDERR output of a commond without saving it to a file?

search in vain? Does bash/bash2 not have this ability? Is this ability simply not indexed on google? What search engine can find my answer?

Maybe /dev/null will help me in the current process


Conceptor's picture
Submitted by Conceptor on Wed, 02/02/2005 - 19:22.

this is making a custom file descriptor with value three . this override the bash/shell default file descriptors. and save the current stdout value you can make it 4 6..9 .do not do 5 .

exec 3>&1 

execute your command and pipe it to grep

command 2>&1 >&3 3>&- | grep word  3>&-  
#1       2   3    4   5  6   7      8
  1. your command
  2. redirect the output at the default stdout
  3. this will call the the saved value which u make for it save
  4. close file descriptor 3 for 'grep'
  5. the world famous pipe
  6. grep #man grep for details
  7. your needed words
  8. close output file descriptor 3.

close the upper exec 3>&1 to resume work on your shell as defaults :

exec 3>&-  

Diaa Radwan


Pronco's picture
Submitted by Pronco on Wed, 02/02/2005 - 21:47.

stderr must be one of the worlds worst inventions..

2>&1 1> /dev/null

That redirects stderr to stdout and stdout to /dev/null.

foo 2>&1 | grep "whatever"

BTw, conceptor yours is appreciated and thank you for your plentiful information


I used to be indecisive .. but now I'm not so sure


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.