2016-11-04 65 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即可。