On UNIX like operating systems, an IP address can be sorted using the utility sort, part of the GNU Core utils

 sort -n -t . -k 1,1 -k 2,2 -k 3,3 -k 4,4

-n, –numeric-sort          compare according to string numerical value

-t, –field-separator=SEP  use SEP instead of non-blank to blank transition

-k, –key=POS1[,POS2] start a key at POS1 (origin 1), end it at POS2

If you like a well written explanation of this, I invite you to read this article by Paul Heinlein.

Be Sociable, Share!