Sort IP address

In FreeBSD 7, I used this command to sort a file with IP addresses:
sort -n -t . -k 1,1 -k 2,2 -k 3,3 -k 4,4

Now, in FreeBSD 10, that command does not work.

I tried:
sort -t. -k1n,1 -k2n,2 -k3n,3 -k4n,4
sort -t . -k 1,1n -k 2,2n -k 3,3n -k 4,4n

But I get nothing.

This is the input file:
Code:
11.1.2.3
10.0.0.1
10.0.0.200
10.0.0.100
10.0.0.30
10.0.0.2
2.0.0.10

What is the problem?

Code:
OS=FreeBSD 10.1-RELEASE sparc64
sort version = 2.3 FreeBSD
 
Use GNU sort (it's in the base system). It does what you want (with the first invocation). Maybe you have set WITHOUT_GNU in your /etc/src.conf, build from source and have another sort utility? Try to give the explicit path: /usr/bin/sort -n ...
 
Use GNU sort (it's in the base system). It does what you want (with the first invocation). Maybe you have set WITHOUT_GNU in your /etc/src.conf, build from source and have another sort utility? Try to give the explicit path: /usr/bin/sort -n ...

So, is this a bug with the BSD-sort?
 
sort -n -t. -k1 -k2 -k3 -k4 works here on FreeBSD 10-STABLE amd64:
Code:
2.0.0.10
10.0.0.1
10.0.0.2
10.0.0.30
10.0.0.100
10.0.0.200
11.1.2.3

The first form of the command shown in post #1 works also, although it is redundant. The other forms seem like parameter parsing would not work.
 
Works fine for me too on 10.1-RELEASE amd64

Code:
# sort --version
2.3-FreeBSD
# sort -nt. -k1 -k2 -k3 -k4 test.txt
2.0.0.10
10.0.0.1
10.0.0.2
10.0.0.30
10.0.0.100
10.0.0.200
11.1.2.3
 
I checked some other architectures and it works on my i386 router with FreeBSD 10.1-STABLE r281682 and an armv6 Beaglebone with 11.0-CURRENT r279514. So a sparc64 issue as wblock@ mentioned certainly could be the case.
 
Back
Top