Skip to content

Instantly share code, notes, and snippets.

@vietdien2005
Last active April 8, 2020 09:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vietdien2005/5d18bb8a3bd77bdd46b701a102fcbd08 to your computer and use it in GitHub Desktop.
Save vietdien2005/5d18bb8a3bd77bdd46b701a102fcbd08 to your computer and use it in GitHub Desktop.
Counting IP Addresses in a Log File
  • Command
grep -o "[0-9]\+\.[0-9]\+\.[0-9]\+\.[0-9]\+" /var/log/nginx/access.log
  • Unique IPs
grep -o "[0-9]\+\.[0-9]\+\.[0-9]\+\.[0-9]\+" /var/log/nginx/access.log | sort | uniq
  • Number of times each IP
grep -o "[0-9]\+\.[0-9]\+\.[0-9]\+\.[0-9]\+" /var/log/nginx/access.log | sort | uniq -c

Or

grep -o "[0-9]\+\.[0-9]\+\.[0-9]\+\.[0-9]\+" httpd.log | sort | uniq -c | sort -n
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment