我尝试使用sed在以下文件的[B块]之后插入一行:
[Block A]
line 1
line 2
[Block B]
line 1
line 2
[Block C]
line 1
line 2
我使用的命令:
sed '/\[Block B\]/,/^$/a\inserted line' file
正确/期望的结果应该是:
[Block B]
line 1
line 2
inserted line
但是,我得到了这个:
[Block B]
inserted line
line 1
inserted line
line 2
inserted line
请告诉我如何使用sed获得所需的结果。谢谢!
最佳答案
sed -e '/\[Block B\]/{:a;n;/^$/!ba;i\inserted line' -e '}'
关于bash - 匹配文本块后使用sed插入一行,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/11183469/