Sed附加线 [英] Sed Append Line
本文介绍了Sed附加线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
sed是否有命令在匹配的行之后追加行?我尝试四处搜寻,但对结果有些困惑.
Does sed have a command to append a line after a matched line? I tried searching around but was a bit confused with the results.
我想让它匹配
#address=/doubleclick.net/127.0.0.1
并在其下方添加一行,如
And add a line below it like
#address=/doubleclick.net/127.0.0.1
address=/anotherurl/ipaddress
这可能吗?
推荐答案
您可以在 sed
中使用 a
(附加)命令:
You can use the a
(append) command in sed
:
$ sed -i '/^#address=\/doubleclick.net\/127.0.0.1$/a\
> address=/anotherurl/ipaddress' file.txt
或者您可以使用 s
(替代)命令:
Or you can use s
(substitute) command:
$ sed -i 's@^#address=/doubleclick.net/127.0.0.1$@&\naddress=/anotherurl/ipaddress@' file.txt
注意: $
和>
是bash提示.
Note: $
and >
are bash prompt.
这篇关于Sed附加线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文