4 ms·
(You sound like someone who would probably know this, but a lot of people don't). Note that in general "sort -nu" is not equivalent to "sort -n | uniq", althou
by tzs 6y ago
(You sound like someone who would probably know this, but a lot of people don't).
Note that in general "sort -nu" is not equivalent to "sort -n | uniq", although in this particular case they are. If you have more than one field on the line, they can differ.
For example, if the input is:
3 first
2 second
3 second
1 second
2 first
1 first
then this is the "sort -nu" output:
1 second
2 second
3 first
whereas "sort -n | uniq" gives:
1 first
1 second
2 first
2 second
3 first
3 second
I'm a bit confused as to how "sort -nu" chooses which record to print when there are more than one with the same key. I would have expected the chosen record to be the one that would have come first in "sort -n" output, so that "sort -n | sort -nu" would be equivalent to "sort -nu", but that is not the case. The pipe gives:
1 first
2 first
3 first
It is as if -nu automatically adds -s.
- asicsp 6y agomanual for -u option says "output only the first of an equal run" which is effectively same as what -s option does