[CentOS] [OT] Bash help

Robert Arkiletian robark at gmail.com
Wed Oct 25 16:33:34 UTC 2017


On Wed, Oct 25, 2017 at 9:02 AM, Mark Haney <mark.haney at neonova.net> wrote:
> I know this is for CentOS stuff, but I'm at a loss on how to build a script
> that does what I need it to do.  It's probably really logically simple, I'm
> just not seeing it.  Hopefully someone will take pity on me and at least
> give me a big hint.
>
> I have a file with two columns 'email' and 'total' like this:
>
> me at example.com 20
> me at example.com 40
> you at domain.com 100
> you at domain.com 30
>
> I need to get the total number of messages for each email address.  This
> type of code has always been the hardest for me for whatever reason, and
> honestly, I don't write many scripts these days. I'm struggling to get
> psuedocode that works, much less a working script. I know this is off topic,
> and if it gets modded out, that's fine.  I just can't wrap my brain around
> it.
>

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]



More information about the CentOS mailing list