linux 中实现部分取反

 

001、测试文件(实现仅提取==1185== 和 其他不包含==数字==的行)

[root@pc1 test2]# ls
a.txt
[root@pc1 test2]# cat a.txt  ## 测试文件
==1185==
abcadoiafa
==1120==
asvgaoj
fajsdfja
==3875==
yuerdded
==1130==
afsdalj
==1185==

 

002、sed实现

[root@pc1 test2]# ls
a.txt
[root@pc1 test2]# cat a.txt         ## 测试文件
==1185==
abcadoiafa
==1120==
asvgaoj
fajsdfja
==3875==
yuerdded
==1130==
afsdalj
==1185==
[root@pc1 test2]# sed -n '/^==1185==\|^[^==]/p' a.txt    ## 部分取反
==1185==
abcadoiafa
asvgaoj
fajsdfja
yuerdded
afsdalj
==1185==

 

003、grep实现

[root@pc1 test2]# ls
a.txt
[root@pc1 test2]# cat a.txt        ## 测试数据
==1185==
abcadoiafa
==1120==
asvgaoj
fajsdfja
==3875==
yuerdded
==1130==
afsdalj
==1185==
[root@pc1 test2]# grep -E "^==1185==|^[^==]" a.txt    
==1185==
abcadoiafa
asvgaoj
fajsdfja
yuerdded
afsdalj
==1185==

 

 

004、awk实现

[root@pc1 test2]# ls
a.txt
[root@pc1 test2]# cat a.txt
==1185==
abcadoiafa
==1120==
asvgaoj
fajsdfja
==3875==
yuerdded
==1130==
afsdalj
==1185==
[root@pc1 test2]# awk '$0 ~ /^==1185==/ || $0 !~ /^==/' a.txt
==1185==
abcadoiafa
asvgaoj
fajsdfja
yuerdded
afsdalj
==1185==

 。

 

posted @ 2023-09-20 11:59  小鲨鱼2018  阅读(84)  评论(0)    收藏  举报