使用sed

时间:2019-11-11 19:58:37

标签: sed

我知道如何通过sed替换字符串:

sed -i "s|.*#app-${BRANCH}-log.*|    Path ${LOG_PATH}    #app-${BRANCH}-log|" /etc/td-agent-bit/td-agent-bit.conf

这适用于类似文件的文件

[INPUT]
Name tail
Path /var/lib/docker/containers/f774c1a3689dfffb2528833ac2ded629c3b1873fd3af96fe0cf1f041f22f88d8/f774c1a3689dfffb2528833ac2ded629c3b1873fd3af96fe0cf1f041f22f88d8-json.log  #app-develop-log
Tag app.develop
Interval_Sec 1

但是如何替换下一行?例如:

#This line just for triggering sed
And this one must be replaced

有什么主意吗?对不起,我的英语太差了。

1 个答案:

答案 0 :(得分:1)

使用GNU sed:

sed '/^#This line just for triggering sed$/{n;s/.*/foo/}' file

输出:

#This line just for triggering sed
foo

请参阅:man sed