http://www.madboa.com/geek/sort-addr/
sort -n -t . -k 1,1 -k 2,2 -k 3,3 -k 4,4
The long answer. More than once I’ve been confronted with a list of IP addresses that I’ve wanted to sort into numeric order. Trouble is, the dotted-quad notation isn’t sort-friendly. Consider the following raw list of addresses.
$ cat addresses.txt
129.95.30.40
5.24.69.2
19.20.203.5
1.2.3.4
19.20.21.22
5.220.100.50
Without options, sort will rely on alphabetic order, which certainly won’t do what you want:
$ sort addresses.txt
1.2.3.4
129.95.30.40
19.20.203.5
19.20.21.22
5.220.100.50
5.24.69.2
There are so many mistakes in this ordering I’m not even going to try to list them all.