Hint: Sort first to group duplicates, then uniq removes repeats [OK]
Common Mistakes:
Not sorting first, so uniq misses duplicates
Expecting original order instead of sorted
Confusing uniq output with counting duplicates
4. You run uniq file.txt | sort to remove duplicates and sort lines, but duplicates remain. What is the likely problem?
medium
A. uniq only removes adjacent duplicates, so sorting after uniq misses duplicates
B. sort command is not working without options
C. file.txt is empty, so no output
D. uniq requires -c option to remove duplicates
Solution
Step 1: Understand uniq behavior
Uniq removes only adjacent duplicate lines, so if duplicates are scattered, it won't remove them.
Step 2: Analyze command order effect
Sorting after uniq means duplicates are not grouped before uniq runs, so duplicates remain.
Final Answer:
uniq only removes adjacent duplicates, so sorting after uniq misses duplicates -> Option A
Quick Check:
uniq needs sorted input to remove all duplicates [OK]
Hint: Sort before uniq to group duplicates for removal [OK]
Common Mistakes:
Thinking uniq removes all duplicates regardless of order
Believing sort alone removes duplicates
Using uniq -c instead of uniq for removal
5. You have a log file access.log with many repeated IP addresses scattered randomly. You want a sorted list of unique IPs. Which command pipeline correctly achieves this?
hard
A. cat access.log | uniq | sort
B. uniq access.log | sort
C. sort -u access.log
D. uniq access.log | sort -u
Solution
Step 1: Understand sort -u option
sort -u sorts and removes duplicates in one step efficiently.
Step 2: Why others fail
Options A, B, and D all apply uniq before sorting, missing non-adjacent duplicates since IPs are scattered randomly.
Final Answer:
sort -u access.log -> Option C
Quick Check:
sort -u = sorted unique lines in one command [OK]
Hint: Use sort -u for sorted unique lines in one step [OK]
Common Mistakes:
Using uniq before sort, missing duplicates
Not knowing sort -u combines sorting and uniqueness
Using unnecessary cat command
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.