Results 1 to 10 of 13
Dear All,
Need a help with one problem i m facing.
I have a file which has a series of IP addresses in 1st column and no.of hits by that ...
- 09-27-2010 #1Just Joined!
- Join Date
- Sep 2010
- Posts
- 6
Need help with sorting !!
Dear All,
Need a help with one problem i m facing.
I have a file which has a series of IP addresses in 1st column and no.of hits by that IP in the 2nd column. as below
97.208.3.25 357
97.233.255.196 791
97.233.255.198 703
97.233.255.202 694
97.233.255.205 8
97.233.255.210 406
97.233.255.211 845
97.233.255.212 668
97.233.255.215 384
97.233.255.217 419
97.233.255.223 775
97.233.255.226 344
97.233.255.232 660
97.233.255.242 50
97.233.255.250 483
97.233.255.251 824
97.208.3.25 73
97.233.255.196 323
97.233.255.198 276
97.233.255.202 275
97.233.255.205 431
97.233.255.211 387
97.233.255.212 351
97.233.255.215 510
97.233.255.217 147
I want to script it such that i get the max hit value of unique IP addresses.
for eg .IP 97.233.255.217 has got two values 419 & 147. in this i should get the IP and value 419 only.Similarly for IP 97.233.255.215 i shud get the value 510 and the IP only.
Hope my question is clear. Also i need it in bash.
- 09-27-2010 #2Getīs the job done, but this is terrible ineffective code.Code:
for a in `awk '{ print $1 }' <PATH_TO_LIST_FILE> | sort | uniq`; do grep $a <PATH_TO_LIST_FILE> | sort -rn -k2 | head -n 1 ; done
It can surely be done with awk alone, maybe someone more experienced with awk can give some advise
Last edited by Irithori; 09-27-2010 at 12:15 PM.
You must always face the curtain with a bow.
- 09-27-2010 #3Just Joined!
- Join Date
- Sep 2010
- Posts
- 6
Cool script dude...its working....
Thanks a lot !!
- 09-27-2010 #4
yw.
It should maybe be rewritten using either only perl or only awk.You must always face the curtain with a bow.
- 09-27-2010 #5Code:
awk 'END { for (IP in ip) print IP, ip[IP] } $2 > ip[$1] { ip[$1] = $2 }' infile
- 09-29-2010 #6Just Joined!
- Join Date
- Sep 2010
- Posts
- 6
@Irithori
yup i know....but i m weak in perl scripting so dint attempt it
....
also ur script worked but it goes in a loop ...so i took that output in another file and then used uniq on it....
- 09-29-2010 #7Just Joined!
- Join Date
- Sep 2010
- Posts
- 6
@radoulov
thanks for this script....it works efficiently...
needed one more addition....
what if i have a 3rd and 4th column as hour and min and i want the hour and minute output also when the max count had occurred.
for eg
97.233.255.217 419 12 52
97.233.255.217 198 12 30
in this it should diplay the 3rd and 4th column also.
- 09-29-2010 #8Code:
awk 'END { for (IP in ip) print IP, ip[IP] } $2 > ip[$1] { ip[$1] = $2 FS $3 FS $4 }' infile
- 09-29-2010 #9Just Joined!
- Join Date
- Sep 2010
- Posts
- 6
@radoulov
Hi it is giving a wrong output when in include $3 & $4 also.
the first code worked properly.
I have uploaded the raw data(sample.zip) for your reference if needed.
- 09-29-2010 #10
..or you can try and modify it yourself for your needs.
You must always face the curtain with a bow.


Reply With Quote