Bird
0
0

Which of the following is the correct syntax using a pipe to sort a file named data.txt and remove duplicate lines?

easy📝 Syntax Q12 of 15
Linux CLI - Text Processing
Which of the following is the correct syntax using a pipe to sort a file named data.txt and remove duplicate lines?
Asort data.txt | uniq
Buniq data.txt | sort
Csort -u data.txt
Duniq -s data.txt
Step-by-Step Solution
Solution:
  1. Step 1: Understand the order of commands

    To remove duplicates correctly, lines must be sorted first so duplicates become adjacent.
  2. Step 2: Check each option

    sort data.txt | uniq sorts then pipes to uniq, which removes adjacent duplicates. uniq data.txt | sort runs uniq first, which won't remove all duplicates if unsorted. sort -u data.txt uses sort -u which is valid but not the pipe syntax asked. uniq -s data.txt is invalid syntax.
  3. Final Answer:

    sort data.txt | uniq -> Option A
  4. Quick Check:

    Sort before uniq to remove duplicates = A [OK]
Quick Trick: Always sort before uniq to remove duplicates correctly [OK]
Common Mistakes:
  • Running uniq before sort
  • Using invalid uniq options
  • Confusing sort -u with uniq

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Linux CLI Quizzes