开发者

G++ and sed pipeline

开发者 https://www.devze.com 2022-12-18 07:36 出处:网络
I would like to replace all \"no\" by \"on\" in the console output of g++. I tried $ g++ | sed -e \'s/no/on/g\'

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-app开发者_运维技巧le-darwin9-g++-4.0.1: on input files


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
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号