Mission 7 of 30

Pipes and Filters

Build a small report by connecting focused commands.

Combine small commands into useful pipelines for sorting, counting, cutting, translating, and formatting text.

45–55 min Week 1 · Terminal basics Ubuntu terminal
Your outcome: You see the command line as a set of Lego bricks, not one giant memorization test.
Practice inside ~/linux-practice. Check your setup before you begin. Prerequisite: Redirection Operators .

What you’ll practice

  • Use pipes
  • Sort and deduplicate text
  • Extract and reshape columns

The mental model

  • A pipe sends stdout from one command into stdin of the next.
  • sort | uniq is a classic pattern.
  • Filters transform text without opening an editor.

Try it in your terminal

Sort and count

Safe in practice folder

Sorts lines and counts adjacent duplicates after sorting.

Run from ~/linux-practice

cd ~/linux-practice
echo -e 'banana\napple\ncherry\napple' > fruits.txt
sort fruits.txt | uniq -c

Translate characters

Safe in practice folder

Transforms text through a pipeline.

Run from ~/linux-practice

echo 'Hello World' | tr 'a-z' 'A-Z'
echo 'Hello World' | tr ' ' '_'

Cut and align fields

Safe in practice folder

Extracts fields and prints a simple table.

Run from ~/linux-practice

echo 'Name:Age:City' > people.txt
echo 'Jane:25:London' >> people.txt
cut -d: -f1,3 people.txt
column -t -s: people.txt

Put it into practice

  1. Create animals.txt and count duplicates.
  2. Use cut to show selected fields.

Check your result

The pipeline produces a sorted, counted report.

Common mistakes

  • You run `cat fruits.txt | uniq -c` and duplicates still appear. `uniq` only removes *adjacent* duplicates. If 'apple' shows up on line 1 and line 5, `uniq` sees them as different entries. Always `sort` first, then `uniq`. This is the most common pipe mistake I've seen.

Check your understanding

Explain these in your own words. If you’re unsure, revisit the examples before moving on.

  1. What does the | symbol do?
  2. Why is sort often used before uniq?

Your practice, your pace

Loading saved progress…

Discussion

Continue the conversation about this guide. Loading comments connects to GitHub Discussions through giscus.

Open community discussions on GitHub

Check before you copy

This command needs care. Read its context, confirm the target and location, and keep a recovery path.

Copying does not run a command.