- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Scripting Query
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-17-2011 02:01 AM
тАО01-17-2011 02:01 AM
I am trying to find out the IP address that has got written most frequently to my access_log file. The file is a few thousand lines and therefore it is not practical to view this manually. I have tried to select the first column in the access_file and print it, sort it and simply eyeball the result but with so many different addresses there must be a more solid way of doing it?
i.e.
# cat access_log | awk '{print $1}' | sort -rn > /tmp/access.txt
And this leads on to my next question which is if I was looking for the most frequent entry in a file but not necessarily an IP address how could I get it if it wasn't delimited by colums and could be of any alphanumerical value?
Regards,
D.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-17-2011 02:39 AM
тАО01-17-2011 02:39 AM
Re: Scripting Query
Write a trivial awk or perl script using hash arrays.
Regards,
Goran
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-17-2011 04:29 PM
тАО01-17-2011 04:29 PM
SolutionTry:
awk '{print $1}' access_log | sort | uniq -c | sort -rn > /tmp/access.txt
>if it wasn't delimited by columns and could be of any alphanumerical value?
Are you trying to find the most frequently occurring "word" in a file?
You could use tr(1) to convert your separators to a newline then use the above sort/uniq/sort pipeline. (Removing blank lines first.)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-17-2011 11:30 PM
тАО01-17-2011 11:30 PM
Re: Scripting Query
you could use 'webalizer' to parse the access_log for you, as it does all the sorting on your behalf, then use curl to pull back the stats page.
regards
Matt
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-19-2011 01:56 AM
тАО01-19-2011 01:56 AM
Re: Scripting Query
Denis, yes I am trying to find the most frequently used word in a file. Are there any alternatives to 'tr' or is this the only way of doing it? What would the command look like to obtain this.
R,
D.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-19-2011 08:43 AM
тАО01-19-2011 08:43 AM
Re: Scripting Query
Thanks for the feedback! Spot on Dennis with the tr command for the non delimited file also.
Using 'tr' I replaced the spaces with a new line and redirected the output to a new file then used the sort/uniq/sort pipeline as suggested and it produces the desired result.
Regards,
D.