Text processing
8 minsort, and why uniq needs it
uniq only collapses adjacent lines.
sort compares bytes, not meaning. Under LC_ALL=C — which is what this shell uses, and what a script should set — every uppercase letter sorts before every lowercase one, and 100 sorts before 9.
-n compares numbers instead. A line with no number in it counts as zero, which is why a mixed file comes out in an order that looks arbitrary.
Try this
uniq collapses runs of adjacent equal lines. It does not know about lines it has already passed, which is why unsorted input silently produces duplicates and why sort | uniq is one idiom rather than two commands.
sort -u does both in one pass, and uniq -c adds the counts.
Try this
$
Files
| Mode | Links | Size | Name |
|---|---|---|---|
| -rw-r--r-- | 1 | 48 | words.txt |