Skip to content

Instantly share code, notes, and snippets.

@josuecau
Last active Aug 17, 2020
Embed
What would you like to do?
#!/usr/bin/env bash
# List the most frequently used words in a text.
[ $# -ge 1 ] && [ -f "$1" ] && input="$1" || input="-"
# shellcheck disable=SC2002
cat "$input" |
tr -cs '[:alpha:]' '\n' | # Split words and drop non-alphabetic characters.
tr '[:upper:]' '[:lower:]' | # Put it all to lowercase.
sed '/../!d' | # Remove lines with less than two chars.
sort | uniq -c | sort -k1nr | # Deduplicate and sort by number of occurrences.
awk '$1 > 1' # Keep words with more than one occurrence.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment