Sorting and Finding Uniques
Concept & Overview
Imagine sorting a deck of cards where duplicates are scattered all over. To easily spot and remove duplicates, you'd first group the identical cards together. In Linux, the uniq command filters out repeating lines, but it has a catch: it only detects duplicates that are right next to each other!
- To remove all duplicates from a messy list, you must first sort the lines using sort and then pass the result to uniq. E.g., sort raw.txt | uniq organizes and cleans the list in one go.
names.txt contains duplicate names. Connect sort and uniq with a pipe to find all unique names alphabetically, and save them in unique_names.txt.Command Syntax Reference
| Command / Syntax | Description |
|---|---|
sort names.txt | Sort lines of names.txt alphabetically |
sort names.txt | uniq > unique_names.txt | Sort and filter duplicates into a file |
Verification Objectives
These conditions will be automatically verified when you run commands inside the interactive terminal simulator:
- ○Use the "sort" command on names.txt
- ○Pipe sorted output into "uniq" command
- ○Create file "unique_names.txt"
- ○Verify content has unique sorted names
Ready to complete Quest 25?
Test your skills live in the browser terminal with an emulated Linux filesystem, real-time command evaluation, and instant step-by-step hints.