linux中sed命令删除匹配行及其下一行


 

1、测试数据

[root@rhel7pc1 test]# ls
a.txt
[root@rhel7pc1 test]# cat a.txt    ## 测试数据 1 k d f
2 x c g
3 z c b
4 e w e
5 z c f
6 e d g

 

2、删除匹配行及其下一行

[root@rhel7pc1 test]# ls
a.txt
[root@rhel7pc1 test]# cat a.txt
1 k d f
2 x c g
3 z c b
4 e w e
5 z c f
6 e d g
[root@rhel7pc1 test]# sed '/x/{N; d}' a.txt    ## 删除匹配x的行及其下一行。 1 k d f
4 e w e
5 z c f
6 e d g

 

3、删除匹配行的下一行

[root@rhel7pc1 test]# ls
a.txt
[root@rhel7pc1 test]# cat a.txt
1 k d f
2 x c g
3 z c b
4 e w e
5 z c f
6 e d g
[root@rhel7pc1 test]# sed '/x/ {n; d}' a.txt    ## 删除匹配x行的下一行 1 k d f
2 x c g
4 e w e
5 z c f
6 e d g

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM