Appearance
Approach: Pipeline: squeeze spaces to newlines, sort, uniq -c, sort by count descending, print word then count.
Complexity: O(n log n) time dominated by sort
shell
# Read from the file words.txt and output the word frequency list to stdout.
cat words.txt | tr -s ' ' '\n' | sort | uniq -c | sort -rn | awk '{print $2, $1}'