sed删除两个模式之间的行,没有第二个模式,包括第一个模式 [英] sed delete lines between two patterns, without the second pattern, including the first pattern
本文介绍了sed删除两个模式之间的行,没有第二个模式,包括第一个模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的输入文件如下:
[1234]
text
text
text
[3456]
text
text
text
[7458]
text
text
text
我想删除模式之间的所有行,包括FROM_HERE和TO_HERE,
I want to delete all lines between the patterns, including FROM_HERE and excluding TO_HERE.
sed '/FROM_HERE/,/TO_HERE/{//p;d;}'
现在我有:
sed '/^\['"3456"'\]/,/^\[.*\]/{//p;d;}'
,但此命令也不会删除FROM_HERE行。最后的3456输入文件应如下所示:
but this command does not delete the line FROM_HERE too. for 3456 at the end the input file should look like:
[1234]
text
text
text
[7458]
text
text
text
我该如何实现?谢谢。
推荐答案
您可以将模式中的行删除到下一个空白行:
You could delete lines from your pattern to next blank line:
sed '/^\['"3456"'\]/,/^$/{d;}' file
这篇关于sed删除两个模式之间的行,没有第二个模式,包括第一个模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文