在 FreeBSD 上如何替换以特定模式开头的行中的单词?
考虑以下文件内容:
this is to test
that was for test
我想替换以“this”开头的行中的“test”。
为了执行以以下开头的行的替换this
, say:
$ sed '/^this/ s/test/something/' inputfile
this is to something
that was for test
这将取代这个词test
with something
在以以下开头的行上this
.
如果你想替换所有实例test
在匹配线上,提供g
sed 的选项:
sed '/^this/ s/test/something/g' inputfile
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)