Sort IP address – Bash

Sometimes you wonder how to sort IP address from a large pool of IP address consisting different subnets.

Here is a simple command which can do the task for you

Sample input file

sort -t . -k 1,1n -k 2,2n -k 3,3n -k 4,4n /path to file


-t . : Used as field seperator, here (dot) is field seperator
-n : Sorts in numerical value
-k : Sorts the data field using the specific column number, here the sorting starts from first field, then second, and so on.

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Posts