How to string with most number of accurances in log file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to string with most number of accurances in log file
# 1  
Old 09-16-2011
MySQL How to string with most number of accurances in log file

Dear Friends,

I am new to this forum and this is my first thread. How to find the maximum number of occurrences in a log file. A log file contains the list of the ip addresses that makes get request to the server. The script has to find the ip which makes maximum number of requests to the server from its log.

Since I am new to shell script, I feel it little difficult. Kindly give me some clues with which I can move further.

Thanks,
Tamil Pamaran
# 2  
Old 09-16-2011
Welcome to the forum.

You didn't mention about the log file format. If it contains only the IP ADDRESS,
probably you can do something like,

Code:
$ cat f5
54.215.211.198
50.215.211.198
50.215.211.198
51.215.211.198
51.215.211.198
52.215.211.198
52.215.211.198
52.215.211.198
52.215.211.198
53.215.211.198
$ 
$ 
$ sort f5 | uniq -c | sort -nrk1 | head -1
   4 52.215.211.198
$


There are lots of other ways around.
This User Gave Thanks to clx For This Post:
# 3  
Old 09-16-2011
sort | uniq -c

---------- Post updated at 14:15 ---------- Previous update was at 14:12 ----------

anchal_khare is faster. Smilie
# 4  
Old 09-16-2011
Thanks for your quick response friends anchal_khare and sk1418. It worked as I have expected it. Will go through about the commands in MAN pages.

Thanks once again,
Tamil Pamaran
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replace all string matches in file with unique random number

Hello Take this file... Test01 Ref test Version 01 Test02 Ref test Version 02 Test66 Ref test Version 66 Test99 Ref test Version 99 I want to substitute every occurrence of Test{2} with a unique random number, so for example, if I was using sed, substitution would be something... (1 Reply)
Discussion started by: funkman
1 Replies

2. Shell Programming and Scripting

Help in printing n number of lines if a search string matches in a file

Hi I have below script which is used to grep specific errors and if error string matches send an email alert. Script is working fine , however , i wish to print next 10 lines of the string match to get the details of error in the email alert Current code:- #!/bin/bash tail -Fn0 --retry... (2 Replies)
Discussion started by: neha0785
2 Replies

3. Shell Programming and Scripting

Count number of occurrence of a string in file

if there's a file containing: money king money queen money cat money also money king all those strings are on one line in the file. how can i find out how many times "money king" shows up in the line? egrep -c "money king" wont work. (7 Replies)
Discussion started by: SkySmart
7 Replies

4. Shell Programming and Scripting

Segregate a number from a String in the log

Hi, I have below lines in the log file. how to segregate and assign '3904' to a variable. XCMM018I Return Code: 8 Feedback: 0 :&PNUM=3904: (3 Replies)
Discussion started by: johnjs
3 Replies

5. Shell Programming and Scripting

How to search number of occurrences of a particular string in a file through vi editor?

i have one file, i am doing 'vi Filename' now i want to search for particular string and i want to know how many times that string occurs in whole file (5 Replies)
Discussion started by: sheelsadan
5 Replies

6. Shell Programming and Scripting

find string nth occurrence in file and print line number

Hi I have requirement to find nth occurrence in a file and capture data from with in lines (between lines) Data in File. <QUOTE> <SESSION> <ATTRIBUTE NAME='Parameter Filename' VALUE='file1.parm'/> <ATTRIBUTE NAME='Service Name' VALUE='None'/> </SESSION> <SESSION> <ATTRIBUTE... (6 Replies)
Discussion started by: tmalik79
6 Replies

7. Shell Programming and Scripting

How to count number of occurances of string in a file?

Gurus, Need little guidance. I have A.txt and B.txt file. B.txt file contains Unique strings. Sample content of B.txt file for which i cut the fourth column uniquely and output directed to B.txt file And A.txt file contains the above string as a fourth column which is last column. So A.txt... (7 Replies)
Discussion started by: Shirisha
7 Replies

8. Shell Programming and Scripting

How to print the number of lines from a file, the starting string should be passed`

Hi , I have file, which has the below content: line 100 a b c d line300 a s d f s line200 a s d a (3 Replies)
Discussion started by: little_wonder
3 Replies

9. Shell Programming and Scripting

how to search string and number in one file and check in the other file

Hi, Can anyone help in the below problem. file1 has the below contents fileset 999 primary-ilist inode 37020 has invalid dotdot (426094) -> Not exist fileset 999 primary-ilist inode 115016 dup block ->... (9 Replies)
Discussion started by: knshree
9 Replies

10. UNIX for Dummies Questions & Answers

count the number of files which have a search string, but counting the file only once

I need to count the number of files which have a search string, but counting the file only once if search string is found. eg: File1: Please note that there are 2 occurances of "aaa" aaa bbb ccc aaa File2: Please note that there are 3 occurances of "aaa" aaa bbb ccc... (1 Reply)
Discussion started by: sudheshnaiyer
1 Replies
Login or Register to Ask a Question