Menu
Coddy logo textTech

Word Frequency Counter

Part of the Fundamentals section of Coddy's Terminal journey — lesson 81 of 82.

challenge icon

Challenge

Easy

Analyze the file article.txt and count how many times each word appears. Build a pipeline that:

  1. Reads the file content
  2. Converts spaces to newlines (one word per line) using tr ' ' '\n'
  3. Sorts the words alphabetically
  4. Counts occurrences of each word using uniq -c
  5. 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 was

Combine all the commands into a single pipeline using the pipe | operator.

Hint: Start with cat article.txt and chain the commands: tr to split words, sort to group them, uniq -c to count, and sort -rn to order by frequency.

Try it yourself

Terminal

All lessons in Fundamentals