Klaus
Klaus

Reputation: 1251

G++ and sed pipeline

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

Upvotes: 1

Views: 363

Answers (1)

Greg Bacon
Greg Bacon

Reputation: 139521

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

Upvotes: 6

Related Questions