[chenweibo@jump1:~]$ cat ip.txt
tcp 0 0 183.60.177.233:30677 58.215.46.34:32200 ESTABLISHED
tcp 0 0 172.19.160.5:32200 172.19.11.10:57817 ESTABLISHED
tcp 0 0 172.19.160.5:32200 172.19.35.20:65007 ESTABLISHED
tcp 0 0 183.60.177.233:19187 115.238.171.163:32200 ESTABLISHED
tcp 0 0 172.19.160.5:32200 172.16.25.68:24710 ESTABLISHED
tcp 0 0 183.60.177.233:17208 14.17.112.142:32200 ESTABLISHED
tcp 0 0 172.19.160.5:32200 172.19.11.10:50392 ESTABLISHED
tcp 0 0 172.19.160.5:32200 172.19.35.182:64076 ESTABLISHED
tcp 0 0 172.19.160.5:32200 172.19.35.20:65006 ESTABLISHED
tcp 0 0 183.60.177.233:31797 114.111.163.29:32200 ESTABLISHED
tcp 0 0 183.60.177.233:14914 113.107.237.17:32200 ESTABLISHED
tcp 0 0 172.19.160.5:32200 172.19.15.84:54401 ESTABLISHED
tcp 0 0 172.19.160.5:32200 172.19.41.190:59725 ESTABLISHED
tcp 0 0 172.19.160.5:32200 172.19.35.20:65005 ESTABLISHED
tcp 0 0 183.60.177.233:25941 14.17.112.170:32200 ESTABLISHED
tcp 0 0 183.60.177.233:34022 183.136.136.42:32200 ESTABLISHED
tcp 0 0 183.60.177.233:7180 121.14.37.153:32200 ESTABLISHED
tcp 0 0 183.60.177.233:59483 113.106.100.72:32200 ESTABLISHED
tcp 0 0 183.60.177.233:35766 120.132.133.37:32200 ESTABLISHED
tcp 0 0 183.60.177.233:23225 121.9.240.12:32200 ESTABLISHED
tcp 0 0 183.60.177.233:23226 121.9.240.12:32200 ESTABLISHED
统计与ip为172.19.160.5的主机建立连接的IP地址及每个地址所对应的连接数,结果放到result.txt
[chenweibo@jump1:~]$ grep ‘172.19.160.5‘ ip.txt|awk ‘{print $5}‘|awk -F: ‘{a[$1]++;}END{for(i in a
) print i,a[i]}‘
172.19.11.10 2
172.19.41.190 1
172.19.35.182 1
172.19.35.20 3
172.19.15.84 1
172.16.25.68 1
本文出自 “漫漫长路” 博客,谢绝转载!