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.
Your outcome: You see the command line as a set of Lego bricks, not one giant memorization test.
Practice inside
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 folderSorts 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 folderTransforms 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 folderExtracts 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
- Create animals.txt and count duplicates.
- 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.
- What does the | symbol do?
- Why is sort often used before uniq?
Your practice, your pace
Loading saved progress…