[olug] sort -u vs uniq

Ben Hollingsworth obiwan at jedi.com
Mon Mar 13 10:29:47 CDT 2017


I'm sure that sort -n only considers the part that looks like a decimal 
number, ie, the first two octets.  I suspect (without confirmation) that 
"sort -u" is more efficient than "sort | uniq".  I'd run "sort -u" to 
get your unique list in a lexographically-sorted list, and pipe that to 
another command if you want it sorted differently.

sort -u | sort -n

On 03/13/17 10:23, Noel Leistad wrote:
> I'm trying to get a list of uniq IP addresses from a log file. I have 
> a list of ALL IP addresses. Using sort -nu and sort -n | uniq give me 
> 2 different lists.
>
> A stare and compare make me think that sort -nu  only considers the 
> first 2 octets as significant. RTFM of the sort man page indicates 
> sort honors LC_COLLATE.
>
> <appear uninformed>
> LC_COLLATE isn't in env, so I'm assuming it's set at build/compile 
> time when building sort or in the c libraries someplace?
> </appear uninformed -- hardly, stupid probably better tag... and not 
> closed.>
>
> Could this be why the sort -u and uniq return differing output? I 
> don't see anyplace to specify "how much" to consider significant when 
> running sort. Anyone care to offer thoughts?

-- 
*Ben "Obi-Wan" Hollingsworth* obiwan at jedi.com <mailto:obiwan at jedi.com> 
www.Jedi.com <http://www.jedi.com>
The stuff of earth competes for the allegiance I owe only to the
Giver of all good things, so if I stand, let me stand on the
promise that You will pull me through. /-- Rich Mullins/



More information about the OLUG mailing list