Concept Flow - sort and uniq in pipelines
Input lines
sort command
uniq command
Output unique sorted lines
The pipeline takes input lines, sorts them alphabetically, then filters out duplicates to output unique sorted lines.
printf "apple\nbanana\napple\ncherry\nbanana\n" | sort | uniq| Step | Command | Input | Output | Explanation |
|---|---|---|---|---|
| 1 | printf | none | apple banana apple cherry banana | Prints the list of fruits with duplicates |
| 2 | sort | apple banana apple cherry banana | apple apple banana banana cherry | Sorts lines alphabetically, duplicates stay |
| 3 | uniq | apple apple banana banana cherry | apple banana cherry | Removes adjacent duplicate lines |
| 4 | end | N/A | apple banana cherry | Pipeline ends with unique sorted output |
| Variable | Start | After printf | After sort | After uniq | Final |
|---|---|---|---|---|---|
| lines | empty | apple banana apple cherry banana | apple apple banana banana cherry | apple banana cherry | apple banana cherry |
Use 'sort | uniq' in a pipeline to get unique sorted lines. 'sort' arranges lines alphabetically. 'uniq' removes only adjacent duplicates. Pipe output of sort into uniq for correct unique filtering. Without sort, uniq misses non-adjacent duplicates.
sort | uniq together in a bash pipeline?sort doessort command arranges lines in alphabetical or numerical order.uniq does after sortinguniq command removes duplicate adjacent lines, so sorting first groups duplicates together for removal.file.txt and sort the output?sort file.txt comes before uniq.sort file.txt | uniq correctly pipes sorted output to uniq for duplicate removal.names.txt with contents:bob alice bob carol alice bob
sort names.txt | uniq?uniq file.txt | sort to remove duplicates and sort lines, but duplicates remain. What is the likely problem?access.log with many repeated IP addresses scattered randomly. You want a sorted list of unique IPs. Which command pipeline correctly achieves this?sort -u optionsort -u sorts and removes duplicates in one step efficiently.Pass the test and this pattern moves unknown