2016-11-04 73 views
-1

文件格式大:算上IP 猫file.txt的awk的for循环,如果不是数字打印

2 11.22.33.33 
10 33.33.44.55 

我想打印线,$ 1> $ MAX

MAX=10 
cat $ip_file | awk '{counts[$1]++} END{ for (ip in counts) if ($(counts[ip]) > "'${MAX}'") print counts[ip] " " ip } 

的纸条上面做不工作,请帮忙。

回答

0
awk -v max=$MAX '{counts[$1]++} END {for(ip in counts) if(counts[ip]>max) print counts[ip], ip}' ip_file 

使用-v max=$MAX可以得到$MAX的值为awk。另外,不需要滥用这只猫,只需在命令后加上ip_file即可。