Sorting output of AWK array

view story

http://www.unix.com – I need help to sort the output of an awk array Example data Code: data="1 blue 2 green 3 blue 4 yellow 5 blue 6 red 7 yellow 8 red 9 yellow 10 yellow 11 green 12 orange 13 black" My awk line to get output in one line Code: echo "$data" | awk  ' {arr[$2]++; next} END { for (i in arr) { if(arr[i]>1 ) printf "%s(%s) ",i,arr[i]};print "" }' gives this output: Code: red(2) yellow(4) green(2) blue(3) I need to count all hits, then print all with 2 or more hits sorted in one line like this (high to low): Code: yellow( (HowTos)