小编Com*_*PVT的帖子

如何使用sed在模式后编辑下一行?

使用sed,如何搜索以 结尾的行foo,然后编辑以 开头的下一行#bar

或者换句话说,我想#从下一行中删除注释,如果它#barfoo.

例如:

This is a line ending in foo
#bar is commented out
There are many lines ending in foo
#bar commented out again
Run Code Online (Sandbox Code Playgroud)

我试过:

sed -i 's/^foo\n#bar/foo\nbar/' infile
Run Code Online (Sandbox Code Playgroud)

sed

6
推荐指数
2
解决办法
1万
查看次数

标签 统计

sed ×1