awk正则匹配列中指定的字符

★ 范例一
◆ 打印指定列中匹配80开头并以80结束的行
● 关系符号注释
~ 关系操作符
~ 匹配正则
!~ 不匹配正则

[root@xingfujie ~]# cat a.txt
afjdkj 80
lkdjfkja 8080
dfjj 80
jdsalfj 808080
jasj 80
jg 80
xingfujie 80
80 ajfkj
asf 80
80 xingfujie
[root@xingfujie ~]# awk '{if($2~/^80$/)print}' a.txt
afjdkj 80
dfjj 80
jasj 80
jg 80
xingfujie 80
asf 80

★ 范例二
● 范例 2.1
◆ grep -v ffff过滤ipv6的地址,显示:80的行,删除A到Z和_对应的行,判断已:作为分隔符,打印第三列等于80的行。
[root@xingfujie ~]# netstat -nat | grep -v ffff | grep ":80" | tr -d "[A-Z][_]"| awk -F : '{if($3==80)print}'
tcp        0      0 10.15.201.29:38393          123.125.106.196:80             
tcp        0      0 10.15.201.29:38383          60.28.236.116:80               
tcp        0      0 10.15.201.29:44949          60.28.236.112:80               
tcp        0      0 10.15.201.29:41445          60.28.236.116:80               
tcp        0      0 10.15.201.29:47630          60.28.236.112:80               
tcp        0      0 10.15.201.29:48624          60.28.236.116:80                
tcp        0      0 10.15.201.29:48129          60.28.236.116:80               
tcp        0      0 10.15.201.29:48837          60.28.236.112:80               
tcp        0      0 10.15.201.29:50506          60.28.236.112:80               
tcp        0      0 10.15.201.29:53923          60.28.236.112:80      
● 范例 2.2
◆ 不加grep ":80"一样可以查出正确结果
[root@xingfujie ~]# netstat -nat | grep -v ffff | tr -d "[A-Z][_]"| awk -F : '{if($3==80)print}'
tcp        0      0 10.15.201.29:60047          118.67.112.70:80               
tcp        0      0 10.15.201.29:49038          123.125.106.196:80             
tcp        0      0 10.15.201.29:37035          123.125.106.196:80             
tcp        0      0 10.15.201.29:35936          118.67.112.70:80               
tcp        0      0 10.15.201.29:35972          60.28.236.112:80               
tcp        0      0 10.15.201.29:35056          60.28.236.116:80               
tcp        0      0 10.15.201.29:48777          60.28.236.112:80               
tcp        0      0 10.15.201.29:47173          60.28.236.116:80               
tcp        0      0 10.15.201.29:53014          60.28.236.116:80             
tcp        0      0 10.15.201.29:51816          60.28.236.112:80               
tcp        0      0 10.15.201.29:53109          60.28.236.112:80             
tcp        0      0 10.15.201.29:52274          60.28.236.112:80               
tcp        0      0 10.15.201.29:49854          60.28.236.116:80             
tcp        0      0 10.15.201.29:50339          60.28.236.112:80               
tcp        0      0 10.15.201.29:60595          60.28.236.116:80  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值