Bird
0
0

You want to find all lines containing 'error' in a log file, count them, and then sort the count numerically. Which pipeline correctly achieves this?

hard📝 Application Q8 of 15
Linux CLI - Pipes and Redirection
You want to find all lines containing 'error' in a log file, count them, and then sort the count numerically. Which pipeline correctly achieves this?
Agrep 'error' logfile | sort -n | wc -l
Bsort -n logfile | grep 'error' | wc -l
Cwc -l logfile | grep 'error' | sort -n
Dgrep 'error' logfile | wc -l | sort -n
Step-by-Step Solution
Solution:
  1. Step 1: Understand the goal

    First filter lines with 'error', then sort them numerically, then count lines.
  2. Step 2: Check pipeline order

    grep 'error' logfile | sort -n | wc -l filters with grep, sorts the filtered lines numerically, then counts lines with wc -l correctly.
  3. Final Answer:

    grep 'error' logfile | sort -n | wc -l -> Option A
  4. Quick Check:

    Correct command order = filter, sort, count [OK]
Quick Trick: Filter first, then sort, then count [OK]
Common Mistakes:
  • Sorting before filtering
  • Counting before filtering
  • Using wrong command order

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Linux CLI Quizzes