Linux 中 sed命令的反向选择

 

Linux 中 sed命令的反向选择

001、

[root@PC1 test]# ls
a.txt
[root@PC1 test]# cat a.txt                        ## 测试文本
01      02_mn   03      04
05      06      07      08
09      10      11_abc  12
13      14      15_abc  16
17      18_xyz  19      20
[root@PC1 test]# sed -n '/_abc/!p' a.txt          ## 输出匹配_abc以外的行
01      02_mn   03      04
05      06      07      08
17      18_xyz  19      20

image

 。

 

002、

[root@PC1 test]# ls
a.txt
[root@PC1 test]# cat a.txt                  ## 测试数据
01      02_mn   03      04
05      06      07      08
09      10      11_abc  12
13      14      15_abc  16
17      18_xyz  19      20
[root@PC1 test]# sed -n '/_mn\|_abc/!p' a.txt      ## 匹配两个条件反选
05      06      07      08
17      18_xyz  19      20

image

 。

 

posted @ 2025-12-25 14:50  小鲨鱼2018  阅读(4)  评论(0)    收藏  举报