[CentOS] [OT] Bash help

Fri Oct 27 08:07:43 UTC 2017
Proxy <proxy-one at mail.ru>

This thread started as "I'm not sure if this is offtopic" and it ended
as such a great and fun to read discussion. Thank you all for these
great script examples. I really enjoyed reading it. 

On 2017-Oct-25 17:10, m.roth at 5-cent.us wrote:
> Tony Mountifield wrote:
> > In article
> > <b5215baacd93a6e85efc59947f9b8ed9.squirrel at host290.hostmonster.com>,
> >  <m.roth at 5-cent.us> wrote:
> >> Warren Young wrote:
> >> > On Oct 25, 2017, at 10:02 AM, Mark Haney <mark.haney at neonova.net>
> >> wrote:
> >> >>
> >> >> 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 screams out for associative arrays.  (Also called hashes,
> >> > dictionaries, maps, etc.)
> >> >
> >> > That does limit you to CentOS 7+, or maybe 6+, as I recall.  CentOS 5
> >> is
> >> > definitely out, as that ships Bash 3, which lacks this feature.
> >> <snip>
> >> Associative arrays?
> >>
> >> Awk! Awk! (No, I am not a seagull...)
> >>
> >> sort file | awk '{ array[$1] += $2;} END { for (i in array) { print i
> >> "\t"
> >> array[i];}'
> >
> > Why the sort? It doesn't matter in what order the lines are read.
> > Wouldn't this give you the same?
> >
> > awk '{ array[$1] += $2;} END { for (i in array) { print i "\t"
> > array[i];}}' <file
> >
> You're right, not really necessary in this case. I was working with a
> couple of awk scripts here at work, and it was needed in the middle....
> 
>      mark
> 
> _______________________________________________
> CentOS mailing list
> CentOS at centos.org
> https://lists.centos.org/mailman/listinfo/centos