如果test.txt文件是
GREEN Volks RUNNING GREEN Audi STOPPED GREEN Merc RUNNING
我可以grep STOPPED并将其替换为sed,如下所示
grep "STOPPED" test.txt |sed 's/^GREEN/RED/g'
返回以下输出
RED Audi STOPPED
但我想尝试类似
sed -i 's/^GREEN/RED/g'| grep "STOPPED" test.txt的内容,看看输出如下:
GREEN Volks RUNNING RED Audi STOPPED GREEN Merc RUNNING
提前致谢。
答案 0 :(得分:1)
看起来你想要:
sed '/STOPPED/s/^GREEN/RED/'