Skip to content

Instantly share code, notes, and snippets.

@roktas
Last active August 29, 2015 13:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roktas/10010028 to your computer and use it in GitHub Desktop.
Save roktas/10010028 to your computer and use it in GitHub Desktop.
Read a file of text, determine the n most frequently used words, and print out a sorted list of those words along with their frequencies.
#!/bin/sh
# http://franklinchen.com/blog/2011/12/08/revisiting-knuth-and-mcilroys-word-count-programs/
# http://www.slideshare.net/jaguardesignstudio/why-zsh-is-cooler-than-your-shell-16194692
tr -cs A-Za-z '\n' |
tr A-Z a-z |
sort |
uniq -c |
sort -rn |
sed ${1}q
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment