Bird
0
0

You run uniq file.txt | sort to remove duplicates and sort lines, but duplicates remain. What is the likely problem?

medium📝 Debug Q14 of 15
Bash Scripting - Text Processing in Scripts
You run uniq file.txt | sort to remove duplicates and sort lines, but duplicates remain. What is the likely problem?
Auniq only removes adjacent duplicates, so sorting after uniq misses duplicates
Bsort command is not working without options
Cfile.txt is empty, so no output
Duniq requires -c option to remove duplicates
Step-by-Step Solution
Solution:
  1. Step 1: Understand uniq behavior

    Uniq removes only adjacent duplicate lines, so if duplicates are scattered, it won't remove them.
  2. Step 2: Analyze command order effect

    Sorting after uniq means duplicates are not grouped before uniq runs, so duplicates remain.
  3. Final Answer:

    uniq only removes adjacent duplicates, so sorting after uniq misses duplicates -> Option A
  4. Quick Check:

    uniq needs sorted input to remove all duplicates [OK]
Quick Trick: Sort before uniq to group duplicates for removal [OK]
Common Mistakes:
MISTAKES
  • Thinking uniq removes all duplicates regardless of order
  • Believing sort alone removes duplicates
  • Using uniq -c instead of uniq for removal

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes