0
0
Linux CLIscripting~20 mins

Pipe operator (|) in Linux CLI - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Pipe Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
What is the output of this command pipeline?
Consider the following command pipeline:
echo -e "apple\nbanana\ncherry" | grep 'a' | wc -l

What is the output?
Linux CLI
echo -e "apple\nbanana\ncherry" | grep 'a' | wc -l
A1
B3
C2
D0
Attempts:
2 left
💡 Hint
Count lines containing the letter 'a' after filtering.
💻 Command Output
intermediate
2:00remaining
How many lines are printed by this pipeline?
What is the output count of lines from this command?
seq 5 | awk '{print $1 * 2}' | grep -v '^4$'

How many lines are printed?
Linux CLI
seq 5 | awk '{print $1 * 2}' | grep -v '^4$'
A3
B4
C5
D2
Attempts:
2 left
💡 Hint
Check which numbers are filtered out by grep -v '^4$'.
📝 Syntax
advanced
2:00remaining
Which pipeline produces the output 'hello' correctly?
You want to print 'hello' using a pipe. Which command works correctly?
Aecho hello | grep world
Becho hello | echo world
Cecho hello && echo world
Decho hello | cat
Attempts:
2 left
💡 Hint
Remember what the pipe operator does: it sends output of left command as input to right command.
🔧 Debug
advanced
2:00remaining
Why does this pipeline produce no output?
Examine this command:
cat file.txt | grep 'pattern' | grep 'nomatch'

Assuming 'file.txt' contains lines with 'pattern' but none with 'nomatch', why is there no output?
Linux CLI
cat file.txt | grep 'pattern' | grep 'nomatch'
ABecause the second grep filters out all lines, resulting in no output
BBecause cat command fails to read the file
CBecause grep 'pattern' produces an error
DBecause the pipe operator is used incorrectly
Attempts:
2 left
💡 Hint
Think about how grep filters lines and how pipes pass output.
🚀 Application
expert
3:00remaining
Which pipeline counts unique words in a file correctly?
You want to count how many unique words appear in 'document.txt'. Which pipeline produces the correct count?
Acat document.txt | tr ' ' '\n' | sort | uniq | wc -l
Bcat document.txt | sort | uniq | wc -l
Ccat document.txt | tr '\n' ' ' | sort | uniq | wc -l
Dcat document.txt | tr -s ' ' | uniq | wc -l
Attempts:
2 left
💡 Hint
Think about how to split words into separate lines before sorting and counting unique entries.