Bird
0
0

You have a file data.txt with multiple columns separated by spaces. You want to find unique values in the second column only. Which command pipeline works best?

hard🚀 Application Q9 of 15
Bash Scripting - Text Processing in Scripts
You have a file data.txt with multiple columns separated by spaces. You want to find unique values in the second column only. Which command pipeline works best?
Asort data.txt | uniq -f1
Bcut -d ' ' -f2 data.txt | sort | uniq
Cuniq -f1 data.txt | sort
Dcut -d ' ' -f2 data.txt | uniq | sort
Step-by-Step Solution
Solution:
  1. Step 1: Extract second column with cut

    cut -d ' ' -f2 extracts the second column from each line.
  2. Step 2: Sort and remove duplicates

    sort orders the values, uniq removes duplicates.
  3. Final Answer:

    cut -d ' ' -f2 data.txt | sort | uniq -> Option B
  4. Quick Check:

    Extract column, then sort and uniq for unique values [OK]
Quick Trick: Use cut to isolate column before sort and uniq [OK]
Common Mistakes:
MISTAKES
  • Using uniq -f1 incorrectly
  • Not extracting the column first
  • Sorting after uniq instead of before

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes