为什么不sed的替换所有出现? [英] Why does sed not replace all occurrences?
本文介绍了为什么不sed的替换所有出现?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我在bash运行此code:
If I run this code in bash:
echo dog dog dos | sed -r 's:dog:log:'
它给输出:
log dog dos
我
怎样才能使它代替狗的所有出现?
How can I make it replace all occurrences of dog?
推荐答案
您应该添加先按g
修改,使中美战略经济对话执行的全球的替代的图案缓冲区的内容:
You should add the g
modifier so that sed performs a global substitution of the contents of the pattern buffer:
echo dog dog dos | sed -e 's:dog:log:g'
有关sed的一个梦幻般的文档,检查 http://www.grymoire.com/Unix/Sed.html一>。这的全球的标志了说明: http://www.grymoire.com/在Unix / Sed.html#UH-6
For a fantastic documentation on sed, check http://www.grymoire.com/Unix/Sed.html. This global flag is explained here: http://www.grymoire.com/Unix/Sed.html#uh-6
为 GNU的sed的官方文档
可在 HTTP: //www.gnu.org/software/sed/manual/
这篇关于为什么不sed的替换所有出现?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文