首页 > 系统相关 >linux 中删除匹配内容的下一行

linux 中删除匹配内容的下一行

时间:2022-12-08 13:00:10浏览次数:36  
标签:匹配 删除 ## PC1 tac linux test txt root

 

001、

[root@PC1 test]# ls
a.txt
[root@PC1 test]# cat a.txt       ## 测试数据
1
2
3
4
5
6
7
8
[root@PC1 test]# sed '/4/{n;d}' a.txt        ## 删除匹配4的下一行
1
2
3
4
6
7
8

 

 

002、

[root@PC1 test]# ls
a.txt
[root@PC1 test]# cat a.txt
1
2
3
4
5
6
7
8
[root@PC1 test]# sed '/4/{N;d}' a.txt         ## 删除匹配行及其下一行
1
2
3
6
7
8

 

 

003、

[root@PC1 test]# ls
a.txt
[root@PC1 test]# cat a.txt
1
2
3
4
5
6
7
8
[root@PC1 test]# tac a.txt | sed '/4/{n;d}' | tac      ## 删除匹配行的前一行
1
2
4
5
6
7
8
[root@PC1 test]# tac a.txt | sed '/4/{N;d}' | tac      ## 删除匹配行及其前一行
1
2
5
6
7
8

 

标签:匹配,删除,##,PC1,tac,linux,test,txt,root
From: https://www.cnblogs.com/liujiaxin2018/p/16965792.html

相关文章