我想在某些行中替换模式:
我试过了
sed -i 's/pattern/new-string/g' ./file
但这将替换文件中的所有内容。我只想在与另一个模式匹配的那些行上替换模式
有什么想法吗?
您可以使用以下sed命令:
sed -i '/another-pattern/s/pattern/new-string/g' ./file
这将仅在匹配another-pattern
模式的行上执行替换。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句