Bird
0
0

Which of the following is the correct syntax to remove duplicate lines from file.txt and sort the output?

easy📝 Syntax Q12 of 15
Bash Scripting - Text Processing in Scripts
Which of the following is the correct syntax to remove duplicate lines from file.txt and sort the output?
Auniq file.txt | sort
Bsort file.txt | uniq
Csort | uniq file.txt
Duniq | sort file.txt
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct command order

    The file must be sorted first, so sort file.txt comes before uniq.
  2. Step 2: Check syntax correctness

    sort file.txt | uniq correctly pipes sorted output to uniq for duplicate removal.
  3. Final Answer:

    sort file.txt | uniq -> Option B
  4. Quick Check:

    sort first, then uniq = correct syntax [OK]
Quick Trick: Pipe sorted output into uniq: sort file | uniq [OK]
Common Mistakes:
MISTAKES
  • Placing uniq before sort, which fails to remove all duplicates
  • Incorrect pipe placement causing syntax errors
  • Trying to pass file as argument to uniq instead of sort

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes