-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,685
  • 6
  • 33
  • 40

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
  • 36,089
  • 7
  • 43
  • 59