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

 

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

 

posted @ 2022-12-08 12:52  小鲨鱼2018  阅读(163)  评论(0编辑  收藏  举报