linux – 使用sed删除行直到文件结尾
发布时间:2020-12-13 23:49:51 所属栏目:Linux 来源:网络整理
导读:我正在使用sed -n’/ [test1] /,/ [test2] / {/ [test2] /!p}’test.txt temp.txt ..如果我只想要顶部选择,那么效果很好,但我在底部之后. [test1]ABC[test2]123 但是我在[test2]之后,所以复制[test2]直到行结束.所以产生这样的输出, [test2]123 解决方法 试
我正在使用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 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |