【发布时间】:2014-04-15 07:10:47
【问题描述】:
我有一个这样的配置文件:
[whatever]
Do I need this? no!
[directive]
This lines I want
Very much text here
So interesting
[otherdirective]
I dont care about this one anymore
现在我想匹配[directive] 和[otherdirective] 之间的行而不匹配[directive] 或[otherdirective]。
此外,如果没有找到 [otherdirective],则应返回文件末尾的所有行。 [...] 可能包含任何数字或字母。
尝试
我使用sed 尝试过这样的操作:
sed -r '/\[directive\]/,/\[[[:alnum:]+\]/!d
这种尝试的唯一问题是第一行是[directive],最后一行是[otherdirective]。
我知道如何再次通过管道截断第一行和最后一行,但有 sed 解决方案吗?
【问题讨论】: