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

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,

$ 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.

1 Like

sort | uniq -c

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

anchal_khare is faster. :slight_smile:

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