Issue
I'm trying to calculate the number of unique visits on a URL from my apache logs.
Here is what I have so far:
grep -o 'THIS_IS_MY_URL' other_vhosts_access.log | wc -l
This is working, but I'm not filtering on unique IPs yet. Do you have any idea?
Thanks !
Solution
Those log files are most of the time in the following format:
<IP> - - <TIMESTAMP> <METHOD> <URL> ....
So instead of just using grep, we'll need some more:
- Remove the
-o
from grep so we're getting the whole line where the matching URL is found - Then we can use
cut -d' ' -f1
to get only a list of IP addresses [docs] - Use the bash util
uniq
to filter it to only unique values [docs] - Count the lines using
wc -l
grep 'SEARCH ME' file.log | cut -d' ' -f1 | uniq | wc -l
Answered By - 0stone0 Answer Checked By - Clifford M. (WPSolving Volunteer)