On 10/25/2017 12:33 PM, Robert Arkiletian wrote:> here is a python solution > #!/usr/bin/python > #python 2 (did not check if it works) > f=open('yourfilename') > D={} > for line in f: > email,num = line.split() > if email in D: > D[email] = D[email] + num > else: > D[email] = num > f.close() > for key in D: > print key, D[key] > _______________________________________________That gets me closer, I think.? It's concatenating the number of messages, but it's a start. Thanks. -- Mark Haney Network Engineer at NeoNova 919-460-3330 option 1 mark.haney at neonova.net www.neonova.net
On 10/25/2017 12:41 PM, Mark Haney wrote:> On 10/25/2017 12:33 PM, Robert Arkiletian wrote: >> here is a python solution >> #!/usr/bin/python >> #python 2 (did not check if it works) >> f=open('yourfilename') >> D={} >> for line in f: >> ???? email,num = line.split() >> ???? if email in D: >> ???????? D[email] = D[email] + num >> ???? else: >> ???????? D[email] = num >> f.close() >> for key in D: >> ???? print key, D[key] >> _______________________________________________ > That gets me closer, I think.? It's concatenating the number of > messages, but it's a start. Thanks. >I do this kind of thing on a fairly regular basis with a Perl one-liner: perl -ne '($email, $num) = split; $tot{$email} += $num; END { for $email (keys %tot) { print "$email $tot{$email}\n" } }' < yourfile -- Bowie
On Wed, Oct 25, 2017 at 9:41 AM, Mark Haney <mark.haney at neonova.net> wrote:> On 10/25/2017 12:33 PM, Robert Arkiletian wrote: >> >> here is a python solution >> #!/usr/bin/python >> #python 2 (did not check if it works) >> f=open('yourfilename') >> D={} >> for line in f: >> email,num = line.split() >> if email in D:>> D[email] = D[email] + int(num)>> else:>> D[email] = int(num)>> f.close() >> for key in D: >> print key, D[key] >> _______________________________________________ > > That gets me closer, I think. It's concatenating the number of messages, > but it's a start. Thanks. > > > -- > > Mark Haney > Network Engineer at NeoNova > 919-460-3330 option 1 > mark.haney at neonova.net > www.neonova.net > > _______________________________________________ > CentOS mailing list > CentOS at centos.org > https://lists.centos.org/mailman/listinfo/centos
On Wed, Oct 25, 2017 at 9:59 AM, Robert Arkiletian <robark at gmail.com> wrote:> On Wed, Oct 25, 2017 at 9:41 AM, Mark Haney <mark.haney at neonova.net> wrote: >> On 10/25/2017 12:33 PM, Robert Arkiletian wrote: >>> >>> here is a python solution >>> #!/usr/bin/python >>> #python 2 (did not check if it works) >>> f=open('yourfilename') >>> D={} >>> for line in f: >>> email,num = line.split() >>> if email in D: > >>> D[email] = D[email] + int(num) > >>> else: > >>> D[email] = int(num) > >>> f.close()not to be outdone, python can sort them based on the totals for k in sorted(D, key=d.get, reverse=True): print k, D[k]