Bird
Raised Fist0
Linux CLIscripting~20 mins

Why text processing is Linux's superpower in Linux CLI - Challenge Your Understanding

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Linux Text Processing 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 Linux command pipeline that processes a text file named data.txt:

cat data.txt | grep -i 'error' | sort | uniq -c

What does this command output?
Linux CLI
cat data.txt | grep -i 'error' | sort | uniq -c
AThe total number of lines in data.txt containing 'error' (case-insensitive).
BAll lines from data.txt sorted alphabetically, ignoring case.
COnly lines containing the word 'error' in uppercase, unsorted.
DA list of unique lines containing 'error' (case-insensitive) with their counts, sorted alphabetically.
Attempts:
2 left
💡 Hint
Think about what each command in the pipeline does: grep filters lines, sort orders them, and uniq -c counts duplicates.
🧠 Conceptual
intermediate
1:30remaining
Why is text processing considered Linux's superpower?
Which of the following best explains why text processing tools are considered a superpower in Linux?
ABecause Linux uses text files for configuration, logs, and communication, making text tools essential for automation and troubleshooting.
BBecause Linux only supports text files and cannot handle binary files.
CBecause Linux commands cannot process anything other than text data.
DBecause Linux requires users to manually edit all files without automation.
Attempts:
2 left
💡 Hint
Think about how Linux uses text files in daily system tasks.
🔧 Debug
advanced
2:00remaining
Identify the error in this text processing command
The user wants to extract all lines containing the word 'fail' (case-insensitive) from log.txt and save unique lines sorted by frequency descending. They run:

grep 'fail' log.txt | sort | uniq -c | sort -nr > result.txt

But the output file result.txt is empty. What is the most likely reason?
Linux CLI
grep 'fail' log.txt | sort | uniq -c | sort -nr > result.txt
AThe uniq command requires input to be unsorted to count correctly.
BThe grep command is case-sensitive and misses lines with 'Fail' or 'FAIL'.
CThe sort -nr command sorts alphabetically, not numerically.
DThe output redirection operator '>' is incorrect and should be '>>'.
Attempts:
2 left
💡 Hint
Check if the grep command matches all case variations of 'fail'.
📝 Syntax
advanced
1:30remaining
Which command correctly extracts the third column from a CSV file?
Given a CSV file data.csv with comma-separated values, which command correctly extracts the third column?
Acut -d ';' -f 3 data.csv
Bcut -f 3 data.csv
Ccut -d ',' -f 3 data.csv
Dcut -c 3 data.csv
Attempts:
2 left
💡 Hint
Remember to specify the correct delimiter for CSV files.
🚀 Application
expert
3:00remaining
Create a one-liner to find the top 3 most common words in a text file
Which of the following Linux command pipelines correctly finds the top 3 most common words in file.txt, ignoring case and punctuation?
Atr -cs '[:alpha:]' '\n' < file.txt | tr 'A-Z' 'a-z' | sort | uniq -c | sort -nr | head -3
Bcat file.txt | grep -o '\w+' | sort | uniq -c | sort -nr | head -3
Csed 's/[^a-zA-Z]/ /g' file.txt | tr 'a-z' 'A-Z' | sort | uniq -c | sort -nr | head -3
Dawk '{for(i=1;i<=NF;i++) print $i}' file.txt | sort | uniq -c | sort -nr | head -3
Attempts:
2 left
💡 Hint
Consider how to split words, normalize case, and count frequencies.

Practice

(1/5)
1. Which Linux command is mainly used to search for specific text patterns within files?
easy
A. sed
B. awk
C. grep
D. cat

Solution

  1. Step 1: Understand the purpose of grep

    grep searches files for lines matching a text pattern.
  2. Step 2: Compare with other commands

    sed edits text streams, awk processes text fields, cat displays file content.
  3. Final Answer:

    grep -> Option C
  4. Quick Check:

    Search text patterns = grep [OK]
Hint: Remember: grep means 'global regular expression print' [OK]
Common Mistakes:
  • Confusing sed with grep
  • Thinking awk is for simple text search
  • Using cat to find patterns
2. Which of the following is the correct syntax to replace all occurrences of 'apple' with 'orange' in a file named fruits.txt using sed?
easy
A. sed 'apple=orange' fruits.txt
B. sed 'replace apple with orange' fruits.txt
C. sed -r 'apple -> orange' fruits.txt
D. sed 's/apple/orange/g' fruits.txt

Solution

  1. Step 1: Recall sed substitution syntax

    The correct form is sed 's/old/new/g' to replace all occurrences.
  2. Step 2: Match syntax to options

    Only sed 's/apple/orange/g' fruits.txt uses the correct s/apple/orange/g pattern.
  3. Final Answer:

    sed 's/apple/orange/g' fruits.txt -> Option D
  4. Quick Check:

    sed substitution = s/old/new/g [OK]
Hint: Use s/old/new/g for global replace in sed [OK]
Common Mistakes:
  • Missing 's/' at start of substitution
  • Using wrong delimiters or syntax
  • Forgetting the 'g' flag for global replace
3. What will be the output of the following command?
echo -e "apple\nbanana\napple" | grep -c apple
medium
A. 2
B. 1
C. 3
D. 0

Solution

  1. Step 1: Understand the input lines

    The input has three lines: 'apple', 'banana', and 'apple'.
  2. Step 2: Count lines matching 'apple' with grep -c

    grep -c apple counts lines containing 'apple'. Two lines match.
  3. Final Answer:

    2 -> Option A
  4. Quick Check:

    Count lines with 'apple' = 2 [OK]
Hint: grep -c counts matching lines, not occurrences [OK]
Common Mistakes:
  • Counting total lines instead of matches
  • Confusing occurrences with line count
  • Ignoring the -c flag meaning
4. The command below is intended to print only lines containing 'error' from log.txt. What is wrong?
grep error log.txt | sed 's/error//'
medium
A. It filters lines but removes 'error' text from output
B. It causes a syntax error in sed
C. It removes 'error' but prints all lines, not filtered
D. It does not read the file

Solution

  1. Step 1: Analyze the pipeline commands

    grep error log.txt filters lines with 'error'. Then sed 's/error//' removes 'error' from those lines.
  2. Step 2: Understand the effect on output

    The output shows lines containing 'error' but with the word 'error' removed, which may be unintended.
  3. Final Answer:

    It filters lines but removes 'error' text from output -> Option A
  4. Quick Check:

    grep filters, sed edits text [OK]
Hint: Pipes chain commands; sed edits output after grep filters [OK]
Common Mistakes:
  • Thinking sed filters lines
  • Expecting grep to remove text
  • Assuming syntax error without checking
5. You want to extract the second column from a file data.csv where columns are separated by commas. Which command pipeline correctly does this?
hard
A. grep ',' data.csv | sed 'print $2'
B. cat data.csv | awk -F',' '{print $2}'
C. sed -n '2p' data.csv
D. awk '{print $2}' data.csv

Solution

  1. Step 1: Identify the field separator and extraction tool

    Columns are comma-separated, so awk with -F',' sets comma as delimiter.
  2. Step 2: Check command correctness

    cat data.csv | awk -F',' '{print $2}' uses awk -F',' '{print $2}' to print second column correctly.
  3. Final Answer:

    cat data.csv | awk -F',' '{print $2}' -> Option B
  4. Quick Check:

    awk -F',' prints columns by field [OK]
Hint: Use awk -F',' to split CSV columns [OK]
Common Mistakes:
  • Using sed to print columns incorrectly
  • Forgetting to set field separator in awk
  • Using grep which filters lines, not columns
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard