linux – 使用sed删除行直到文件结尾

我正在使用sed -n’/ [test1] /,/ [test2] / {/ [test2] /!p}’test.txt> temp.txt ..如果我只想要顶部选择,那么效果很好,但我在底部之后.

[test1]
A
B
C
[test2]
1
2
3

但是我在[test2]之后,所以复制[test2]直到行结束.所以产生这样的输出,

[test2]
1
2
3

解决方法:

试试这个命令:

sed -n  '/\(^\[test2\]\)/,$p' test.txt > temp.txt

编辑:

使用扩展正则表达式标志(-r),

 sed -n -r '/(^\[test2\])/,$p' test.txt > temp.txt

相关文章

用的openwrt路由器,家里宽带申请了动态公网ip,为了方便把2...
#!/bin/bashcommand1&command2&wait从Shell脚本并行...
1.先查出MAMP下面集成的PHP版本cd/Applications/MAMP/bin/ph...
1、先输入locale-a,查看一下现在已安装的语言2、若不存在如...
BashPerlTclsyntaxdiff1.进制数表示Languagebinaryoctalhexa...
正常安装了k8s后,使用kubect工具后接的命令不能直接tab补全...