Re: counting ip addresses
- From: Stephan Grein <stephan@xxxxxxxxxxxxxxxx>
- Date: Fri, 27 Oct 2006 16:36:01 +0200
rogv24@xxxxxxxxx wrote:
I am trying to write a routine to provide counts from a list of IP
addresses that are sorted.
example:
2.3.4.5
2.3.4.5
2.3.4.5
10.20.20.40
10.20.20.40
report would like this 2.3.4.5 - sum 3
10.20.20.40 - sum 2
thanks
If you don't mind Python:
#!/usr/bin/python
# emulates uniq -c
# *-* encoding: utf-8 -*-
import sys
res = {}
count = 1
for x in open(sys.argv[1], "r").readlines():
try:
res[x] += 1
except:
res[x] = 1
for key, value in res.items():
print "#%i %s occured %i times!"%(count, key.replace("\n", ""), value)
count += 1
res = {}
Or just use uniq and the -c switch!
HTH
--
Stephan Grein, <stephan at stephan minus rockt dot de>
https://stephan-rockt.de
GnuPG-Key-ID: 0xF8C275D4
FingerPrint: 5B6F 134A 189B A24D 342B 0961 8D4B 0230 F8C2 75D4
.
- References:
- counting ip addresses
- From: rogv24
- counting ip addresses
- Prev by Date: Re: counting ip addresses
- Next by Date: Re: question about setenv
- Previous by thread: Re: counting ip addresses
- Next by thread: Re: counting ip addresses
- Index(es):