Bash Associative Array Sorting By Value
Answer : You can easily sort your output, in descending numerical order of the 3rd field: for k in "${!authors[@]}" do echo $k ' - ' ${authors["$k"]} done | sort -rn -k3 See sort(1) for more about the sort command. This just sorts output lines; I don't know of any way to sort an array directly in bash. I also can't see how the above can give you names ("Pushkin" et al.) as array keys. In bash, array keys are always integers. Alternatively you can sort the indexes and use the sorted list of indexes to loop through the array: authors_indexes=( ${!authors[@]} ) IFS=$'\n' authors_sorted=( $(echo -e "${authors_indexes[@]/%/\n}" | sed -r -e 's/^ *//' -e '/^$/d' | sort) ) for k in "${authors_sorted[@]}"; do echo $k ' - ' ${authors["$k"]} done Extending the answer from @AndrewSchulman, using -rn as a global sort option reverses all columns. In this example, author...