Re: [OT] Bash help

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



On 10/25/2017 01:24 PM, m.roth@xxxxxxxxx wrote:

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];}'

       mark "associative arrays, how do I love thee? Let me tot the arrays..."

Okay, I'm impressed with this one.  I use awk for simple stuff when sed starts getting weird, but this is absolutely elegant. No offense to the other examples, they are all awesome, but I had no idea awk could do this with such little effort.  Well, I know what I'm studying up on this weekend.

--
Mark Haney
Network Engineer at NeoNova
919-460-3330 option 1
mark.haney@xxxxxxxxxxx
www.neonova.net

_______________________________________________
CentOS mailing list
CentOS@xxxxxxxxxx
https://lists.centos.org/mailman/listinfo/centos




[Index of Archives]     [CentOS]     [CentOS Announce]     [CentOS Development]     [CentOS ARM Devel]     [CentOS Docs]     [CentOS Virtualization]     [Carrier Grade Linux]     [Linux Media]     [Asterisk]     [DCCP]     [Netdev]     [Xorg]     [Linux USB]


  Powered by Linux