Subject: bug#20745: I would like to make a request for the sort command

From: Stephane Chazelas <[email-masked]>
Date: Mon, 8 Jun 2015 13:13:54 +0100

2015-06-08 11:16:37 +0200, Erik Auerswald:
[...]
> FWIW I use 'sort' to sort IPv4 addresses in my ping_scan[1] script.
> 
> The info documentation for sort provides another example, log files
> sorted by IP address and time stamp. That specific example even needs
> two runs of sort, because sort lacks built-in support for IP addresses.
> 
> While IPv4 addresses are readily sorted by "sort -s -t '.' -k 1,1n -k
> 2,2n -k 3,3n -k 4,4n", this is not the case for IPv6 addresses.
[...]
> [1] https://www.unix-ag.uni-kl.de/~auerswal/ping_scan/
[...]

Note that IPv4 address in quad-decimal notation can be sorted
with sort -V. Not IPv6 ones.

$ printf '%s\n' 1.2.3.4 1.12.3.4 a:2:b a:1a:b | sort -V
1.2.3.4
1.12.3.4
a:1a:b
a:2:b

IPv6 addresses sort lexically when fully expanded (as in
0000:0000:0000:0000:0000:0000:0000:0001 instead of ::1)

and IPv4 addresses sort lexically as well when in hex notation
(0x7f000001) instead of quad-decimal, or when using the
127.000.000.001 notation (though that one conflicts with the
traditional parsing (inet_addr/gethostbyname) as octal
(010.000.000.001 is traditionaly 8.0.0.1)).

So one can always pre-process the data to convert the IP
addresses in those alternative formats.

-- 
Stephane