Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

duplicate count

Status
Not open for further replies.
Aug 17, 2005
6
US
Greetings,

I have this file that i sorted using perl. the output looks like this:

00:08:30 64.60.192.130(53766)
00:09:30 66.146.162.178(3951)
00:10:44 66.248.53.189(3533)
00:11:20 66.63.165.133(1409)
00:11:27 66.63.165.133(1830)
00:11:34 66.63.165.133(2277)
00:11:42 66.63.165.133(2738)
00:12:52 68.248.232.118(4494)
00:13:04 193.6.38.80(3001)
00:13:06 193.6.38.80(3001)
00:13:08 193.6.38.80(3001)
00:13:10 193.6.38.80(3001)

I am trying to create a shell or perl script that will go through each line, return the ip, and how many times it appeared on the list. I am new to if and else statements, so any help would be greatly appreciated. Thanks.

--Mike
 
Assuming this output is in a file called [tt]file.dat[/tt], try this...
Code:
sed 's/^.* //1;s/(.*$//1' file.dat | sort | uniq -n
Hope this helps.
 
here is a slightly different way:

Code:
cut -d' ' -f2 file.dat|cut -d'(' -f1|sort |uniq -c
 
Oops! Yeah, that's a "[tt]-c[/tt]", not a "[tt]-n[/tt]". Pardon my typo!
 
Thanks SamBones and SkiLift. Both of those gave me the count of duplicated items. This might be a silly question, but how would I list them? I appreciate the help.
 
What do you mean by 'how would I list them'? Both of those suggestions should give you a list of the IP addresses with the count of duplicate items, what additional info do you need to list?

Annihilannic.
 
I don't quite understand. This does list the IPs and how many times they appeared in the list. Isn't that what you asked for?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top