Bird
0
0

Given a file names.txt with contents:

medium📝 Command Output Q13 of 15
Bash Scripting - Text Processing in Scripts
Given a file names.txt with contents:
bob
alice
bob
carol
alice
bob

What is the output of sort names.txt | uniq?
Aalice bob bob carol alice bob
Bbob alice carol
Cbob carol alice
Dalice bob carol
Step-by-Step Solution
Solution:
  1. Step 1: Sort the file contents

    Sorting lines alphabetically gives: alice, alice, bob, bob, bob, carol.
  2. Step 2: Apply uniq to remove duplicates

    Uniq removes repeated adjacent lines, resulting in: alice, bob, carol.
  3. Final Answer:

    alice\nbob\ncarol -> Option D
  4. Quick Check:

    sort + uniq = unique sorted lines [OK]
Quick Trick: Sort first to group duplicates, then uniq removes repeats [OK]
Common Mistakes:
MISTAKES
  • Not sorting first, so uniq misses duplicates
  • Expecting original order instead of sorted
  • Confusing uniq output with counting duplicates

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes