Bird
0
0

Given a file list.txt with contents:

medium📝 Command Output Q4 of 15
Linux CLI - Text Processing
Given a file list.txt with contents:
apple
banana
apple
carrot
banana
banana

What is the output of sort list.txt | uniq -c?
Aapple 2 banana 3 carrot 1
B3 apple 2 banana 1 carrot
Capple banana carrot
D2 apple 3 banana 1 carrot
Step-by-Step Solution
Solution:
  1. Step 1: Sort the file contents

    Sorted lines: apple, apple, banana, banana, banana, carrot.
  2. Step 2: Apply uniq -c to count duplicates

    Counts: 2 apple, 3 banana, 1 carrot.
  3. Final Answer:

    2 apple 3 banana 1 carrot -> Option D
  4. Quick Check:

    sort then uniq -c counts duplicates correctly [OK]
Quick Trick: uniq -c counts duplicates after sorting [OK]
Common Mistakes:
  • Not sorting before uniq
  • Miscounting duplicates
  • Confusing output format

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Linux CLI Quizzes