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