Shorter solution


#1
cat input | tr ' ' '\n' | sort | uniq -c | awk '{a[$1] = a[$1]=="" ? $2 : a[$1]" "$2 } END { for (key in a) { print key" "a[key] } }'| sort -n