How to sort IP addresses
How to sort IP addresses
>cat sortme.txt
192.168.0.5
192.168.0.3
192.168.0.2
192.168.0.1
192.168.0.3
..
>sort -n -t . -k 1,1 -k 2,2 -k 3,3 -k4,4 sortme.txt
192.168.0.1
192.168.0.2
192.168.0.3
192.168.0.3
192.168.0.5
OR to sort and remove duplicates:
>sort -n -t . -k 1,1 -k 2,2 -k 3,3 -k4,4 sortme.txt | uniq
192.168.0.1
192.168.0.2
192.168.0.3
192.168.0.5
>cat sortme.txt
192.168.0.5
192.168.0.3
192.168.0.2
192.168.0.1
192.168.0.3
..
>sort -n -t . -k 1,1 -k 2,2 -k 3,3 -k4,4 sortme.txt
192.168.0.1
192.168.0.2
192.168.0.3
192.168.0.3
192.168.0.5
OR to sort and remove duplicates:
>sort -n -t . -k 1,1 -k 2,2 -k 3,3 -k4,4 sortme.txt | uniq
192.168.0.1
192.168.0.2
192.168.0.3
192.168.0.5