linux 中 sed命令中-n和-N选项

 

001、-n(next),处理匹配行的下一行

[root@PC1 test01]# ls
a.txt
[root@PC1 test01]# cat a.txt                ## 测试数据
01 02 03
04 05 06
07 08 09
10 11 12
13 14 15
[root@PC1 test01]# sed '/07/{n;d}' a.txt     ## 处理匹配07行的下一行, 即删除
01 02 03
04 05 06
07 08 09
13 14 15

 

002、N(NEXT);将匹配行的下一行和当前行当做一行来处理

[root@PC1 test01]# ls
a.txt
[root@PC1 test01]# cat a.txt               ## 测试数据
01 02 03
04 05 06
07 08 09
10 11 12
13 14 15
[root@PC1 test01]# sed '/07/{N;d}' a.txt   ## 将匹配行及匹配行的下一行当做一行来处理
01 02 03
04 05 06
13 14 15
[root@PC1 test01]# cat a.txt
01 02 03
04 05 06
07 08 09
10 11 12
13 14 15
[root@PC1 test01]# sed 'N;/07/d' a.txt    ## N的情况, 可以写在命令的最前面
01 02 03
04 05 06
13 14 15

 。

 

参考:https://mp.weixin.qq.com/s?__biz=Mzg5NzcyNTIyMA==&mid=2247486781&idx=1&sn=7a62f0947e88b6e6c0f51072d61ee4b8&chksm=c06c2b76f71ba260777f08123bfb063988a068ed6f3b68d3573b9345f12a7138cb20fe729662&scene=132#wechat_redirect 

 

posted @ 2023-08-01 09:22  小鲨鱼2018  阅读(370)  评论(0编辑  收藏  举报