|
|
|
|
||||||
| comp.unix.shell Using and programming the Unix shell. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
rogv24@yahoo.com 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 > I would suggest you take a look at the uniq command, and especially to its -c flag. Eric |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
thank you.
Eric Moors wrote: > rogv24@yahoo.com 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 > > > > I would suggest you take a look at the uniq command, > and especially to its -c flag. > > Eric |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
rogv24@yahoo.com 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 |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
On 27 Oct 2006 06:42:28 -0700, rogv24@yahoo.com
<rogv24@yahoo.com> 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 > Is this homework? It's simple in awk. -- What kind of sordid business are you on now? I mean, man, whither goest thou? Whither goest thou, America, in thy shiny car in the night? -- Jack Kerouac |
|
![]() |
| Outils de la discussion | |
|
|