Bird
0
0

Given a file colors.txt with contents:

medium📝 Command Output Q4 of 15
Bash Scripting - Text Processing in Scripts
Given a file colors.txt with contents:
red
blue
red
green
blue
blue

What is the output of sort colors.txt | uniq?
Ablue green red
Bblue blue green red red
Cred blue green
Dblue red green blue
Step-by-Step Solution
Solution:
  1. Step 1: Sort the lines alphabetically

    Sorted lines: blue, blue, blue, green, red, red.
  2. Step 2: Remove duplicate adjacent lines with uniq

    uniq keeps one of each: blue, green, red.
  3. Final Answer:

    blue\ngreen\nred -> Option A
  4. Quick Check:

    sort + uniq removes duplicates and sorts [OK]
Quick Trick: uniq removes only adjacent duplicates, so sort first [OK]
Common Mistakes:
MISTAKES
  • Expecting uniq to remove non-adjacent duplicates
  • Ignoring sorting order
  • Confusing output order

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes