tags:

views:

46

answers:

1

Hello, I would like to replace all "no" by "on" in the console output of g++. I tried

$ g++ | sed -e 's/no/on/g'

But it shows

i686-apple-darwin9-g++-4.0.1: no input files

instead of

i686-apple-darwin9-g++-4.0.1: on input files

+6  A: 

The message is arriving on the standard error, but the shell pipe operator connects the standard output of one process to the standard input of the next.

To reroute stderr, use

$ g++ 2>&1 | sed -e 's/no/on/g'

or

$ g++ |& sed -e 's/no/on/g'

to get

g++: on input files
Greg Bacon
Wow, 59 secs... Thank you! I did not know how to redirect error stream to standard stream.
Klaus
ephemient