Sorting a dotted-decimal notation

Since I had to deal a bit with lists of IP addresses recently I did some research on how to efficiently sort IP addresses in dotted-decimal notation, e.g. You can find how to do it easily when searching the web. Anyway, I found a nice discussion thread started by Rick Moen in " Puzzle: How do you sort IP address lists?" which features a number of solutions.

Here is one of them which is rather efficient and can be done with sort from GNU coreutils (my version as of now is v5.97):

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

Add -u if you want unique output.


Enter your comment. Wiki syntax is allowed:
blog/071107_sorting_a_dotted-decimal_notation.txt · Last modified: 2007-11-07 09:35 by andreas