1

What's the right way to sort a associated array in bash or zsh?

view story
linux-howto

http://unix.stackexchange.com – I'm wondering how should I sort the associated array in bash? I tried the manual, but seems nothing related to sort. The current solution is echo everything out, and use external program i.e key value | sort -k2 That looks inefficient to me. An example of array was: A['192.168.2.2'] = 5 A['192.168.3.2'] = 1 A['192.168.1.1'] = 9 And I'll be looking for the top 2 used IP address, which is 192.168.1.1 and 192.168.2.2, that is, I need to sort this array by it's value. (HowTos)