Sort IP Addresses with GNU sort

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.

Pubblicato da antenore

I'm a free software addicted and an IT senior consultant, married, father and a funny friend

Lascia un commento

Il tuo indirizzo email non sarà pubblicato. I campi obbligatori sono contrassegnati *

Questo sito usa Akismet per ridurre lo spam. Scopri come i tuoi dati vengono elaborati.