I wanted to sort a list of data and I intended to sort it based on its first column which is an IP address.
192.168.1.100
192.168.1.101
192.168.1.110
192.168.1.119
192.168.1.20
192.168.1.30
192.168.1.33
192.168.1.54
192.168.1.64
192.168.1.6
192.168.1.91
On my first machine, I tested sort -n
and It worked as I expected
# coreutils, version: 8.31, release: 23
192.168.1.6
192.168.1.20
192.168.1.30
192.168.1.33
192.168.1.54
192.168.1.64
192.168.1.91
192.168.1.100
192.168.1.101
192.168.1.110
192.168.1.119
But on my second machine, it won't sort properly
# coreutils, version:8.4
192.168.1.100
192.168.1.101
192.168.1.110
192.168.1.119
192.168.1.20
192.168.1.30
192.168.1.33
192.168.1.54
192.168.1.6
192.168.1.64
192.168.1.91
Both machines have the same locale en_US.UTF-8
Why is this happening? How can I resolve it?
locale thousands_sep
returns.
. Probably it's noten_US.UTF-8
(at least not asLC_NUMERIC
). The second machine doesn't use.
as thousands separator. – Kamil Maciorowski Feb 10 '20 at 08:54,
instead of.
. Thanks for your info – annahri Feb 10 '20 at 09:18,
is the right thousands separator inen_US.UTF-8
, so I would say it's the other way around: the first one uses.
instead of,
. – Kamil Maciorowski Feb 10 '20 at 09:24LC_NUMERIC
. – annahri Feb 10 '20 at 09:44-V
aka--version-sort
instead of-n
. It performs a natural sort of things that look like version numbers (and ipv4 addresses look enough like version numbers for it to work). – cas Apr 05 '21 at 09:46