如果大于数字打印,则循环awk

如果大于数字打印,则循环awk,awk,Awk,文件格式:count ip cat file.txt 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 } 上面的纸条不起作用,请帮忙 awk -v max=$MAX '{counts[$1]++} E

文件格式:count ip cat file.txt

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  }
上面的纸条不起作用,请帮忙

awk -v max=$MAX '{counts[$1]++} END {for(ip in counts) if(counts[ip]>max) print counts[ip], ip}' ip_file
使用
-v max=$max
获取awk的
$max
值。此外,无需滥用cat,只需将
ip_文件
放在命令后面即可