1

I found the following code to see which IP Addresses has the highest hits:

FILE=access.log; for ip in cat $FILE |cut -d ' ' -f 1 |sort |uniq; do { COUNT=grep ^$ip $FILE |wc -l; if [[ "$COUNT" -gt "500" ]]; then echo "$COUNT: $ip"; fi }; done

The above code displays the IP address with more than 500 hits (i.e. access on the site by opening the URL)

But that script is too slow. Is there any other code that create the same output?

Plus, how to display the top 10 results only that has the highest hits or access on the URL?

jaYPabs
  • 299
  • 1
  • 4
  • 20

1 Answers1

1

You're re-inventing the wheel. Try this:

sed -e 's/\([0-9]\+\.[0-9]\+\.[0-9]\+\.[0-9]\+\).*$/\1/' -e t -e d access.log | sort | uniq -c
Satanicpuppy
  • 5,946
  • 1
  • 17
  • 18