Skip to content

Instantly share code, notes, and snippets.

@nilsreiter
Last active June 6, 2018 11:04
Show Gist options
  • Save nilsreiter/a9f0fe75fa4d21c27bcce089583d4c63 to your computer and use it in GitHub Desktop.
Save nilsreiter/a9f0fe75fa4d21c27bcce089583d4c63 to your computer and use it in GitHub Desktop.
Count words in plain text file
# This snippet can be used on the command line (tested on a Mac) to get a quick list of word frequencies in the file FILENAME.
# Counting will be done case-insensivitely, i.e., differently cased words will be counted together.
# The result will be written in the file stats.csv (or any other that you give at the end) in the form of a space-separated table
cat FILENAME | tr '[[:punct:][:space:]]' '\n' | sort | uniq -ci | sort -nr | tail -n +2 > stats.csv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment