Word Frequency Counter
Part of the Fundamentals section of Coddy's Terminal journey — lesson 81 of 82.
Challenge
EasyAnalyze the file article.txt and count how many times each word appears. Build a pipeline that:
- Reads the file content
- Converts spaces to newlines (one word per line) using
tr ' ' '\n' - Sorts the words alphabetically
- Counts occurrences of each word using
uniq -c - Sorts the results by count in descending order using
sort -rn
Your output should show the word frequencies with the most common words first:
5 the
3 fox
3 quick
2 dog
2 lazy
2 over
1 a
1 all
1 amused
1 brown
1 by
1 day
1 happy
1 hill
1 is
1 jumps
1 not
1 ran
1 sleeps
1 wasCombine all the commands into a single pipeline using the pipe | operator.
Hint: Start with
cat article.txtand chain the commands:trto split words,sortto group them,uniq -cto count, andsort -rnto order by frequency.
Try it yourself
Terminal
All lessons in Fundamentals
4Directories
Create A DirectoryCopy A DirectoryMove And Rename A DirectoryDelete A DirectoryRecap - Directory Operations7File Content
Head And TailWord CountSort CommandUnique CommandGrep BasicsGrep With FlagsRecap - Text Detective2Navigation
Print Working DirectoryList FilesChange DirectoryAbsolute vs Relative PathsHome And Root DirectoryRecap - Find Your Way8Redirection
Standard OutputOverwrite To A FileAppend To A FileStandard InputStandard ErrorRecap - Log Builder6Wildcards And Patterns
The Star WildcardThe Question Mark WildcardBracket WildcardsCombining WildcardsRecap - Selective Operations9Piping
What Is A PipeChaining Two CommandsChaining Multiple CommandsPipe With GrepRecap - Data Pipeline