使用sed
,如何搜索以 结尾的行foo
,然后编辑以 开头的下一行#bar
?
或者换句话说,我想#
从下一行中删除注释,如果它#bar
以foo
.
例如:
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 ×1