bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: sort


From: Eric Blake
Subject: Re: sort
Date: Wed, 10 May 2006 00:37:41 +0000

> when i try to sort a list of ip addresses (actually, the output of arp -a), i
> get output like this:
> ...
> (192.168.100.110) 00:08:02:5E:2B:4B
> (192.168.100.12) 00:13:72:EF:DC:7F
> (192.168.100.120) 00:13:72:B0:5D:E8
> ...
> 
> there doesn't seem to be a switch to do this sorting properly. currently, i
> will use awk to add a leading 0 if less than 100 and 00 if less than 10,
> however it would be nice to have this feature.

The topic of sorting IP addresses has come up frequently lately; maybe we
should add it to the FAQ.
http://lists.gnu.org/archive/html/bug-coreutils/2006-03/msg00036.html
http://lists.gnu.org/archive/html/bug-coreutils/2006-05/msg00006.html

sort is doing exactly what you asked; the trick is to ask it what you
want.  It seems to me like you want each octet to be treated as
a number, and to sort based on that numeric value.  So, using
-t . to change the sort field separator to ., then using a series
of -k1,1n through -k4,4n to state that field 1 is the primary key
and numerically sorted, field 2 is the second key and numerically
sorted, etc., will get you a sort order more like what you seem
to be wanting.

-- 
Eric Blake





reply via email to

[Prev in Thread] Current Thread [Next in Thread]