I have a text logfile, containing lines of data separated by ” | “
for example
date | time | ip | geo-location (city) | page viewed ......
I need to find the 10 most occuring “page views” in the text file….
each log of page view is listed as:
//pageurl
as the log is on seperate lines I am presuming I would be searching for the page urls between
// [url name] \r\n
how would I code a search to list the top 10 urls and list them into an array….
for example:
$url[0] <<this would be the most occuring url
$url[1] <<thos would be the second most occuring url
and so on….. until I can list them up to:
$url[9] <<which would be the 10th most common url
I am not sure how I would search between the ” // ” and the ” \r\n ”
and then convert the top 10 most common occurrences into an array…
edit: here is 2x lines of my logs, just to help even more if I can
sunday, january 22, 2012 | 16:14:36 | 82.**.***.*** | bolton | //error
sunday, january 22, 2012 | 17:12:52 | 82.**.***.*** | bolton | //videos
Based on the information given, here’s a rather naïve approach:
** Script output: **
It’s not the most optimal solution, and the bigger your log file, the longer it’ll take. To this end, you may be better off logging to a database and querying from that.