-1

file format: count ip cat file.txt

2  11.22.33.33
10 33.33.44.55

I want to print lines which $1 > $MAX

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

the scrip above does not work, please help.

whi
  • 2,453
  • 5
  • 31
  • 35

1 Answers1

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

Use -v max=$MAX to get the value of $MAX to awk. Also, no need to abuse the cat, just put the ip_file after the command.

James Brown
  • 34,397
  • 6
  • 36
  • 56