Combine Grep, Cut, Sort, and Uniq shell commands to filter, and sort an apache (or Nginx, lighthttpd, etc) log file by visitor IP Address counts.

$ grep 'text' /path/to/access.log | cut -d' ' -f1 | sort | uniq -c | sort -r

This is how it works:

Grep: Search the access log file for a particular string (such as a particular resource path or user agent). Pipe the results to:

Cut: Split each line by a space (the apache log file format delimiter) and return the first field (IP address). Also useful are fields 7 and 9 (resource path and status code, respectively in an apache access log).  Pipe the results to:

Words in Posts: 196   Posts: 1   Categories: 6   Users: 1   Comments: 0   

Copyright © 2009 Roger Soucy. All Rights Reserved.
Version 2.0