Bird
0
0

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🚀 Application Q15 of 15
Bash Scripting - Text Processing in Scripts
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?
Acat access.log | uniq | sort
Buniq access.log | sort
Csort -u access.log
Duniq access.log | sort -u
Step-by-Step Solution
Solution:
  1. Step 1: Understand sort -u option

    sort -u sorts and removes duplicates in one step efficiently.
  2. Step 2: Why others fail

    Options A, B, and D all apply uniq before sorting, missing non-adjacent duplicates since IPs are scattered randomly.
  3. Final Answer:

    sort -u access.log -> Option C
  4. Quick Check:

    sort -u = sorted unique lines in one command [OK]
Quick Trick: Use sort -u for sorted unique lines in one step [OK]
Common Mistakes:
MISTAKES
  • Using uniq before sort, missing duplicates
  • Not knowing sort -u combines sorting and uniqueness
  • Using unnecessary cat command

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes