How to sort IP addresses in Linux
Article Number: 4 | Rating: Unrated | Last Updated: Mon, May 21, 2018 9:46 PM
How to sort IP addresses in Linux
Answer:
When you have a file ip.txt contains a list of IP addresses, e.g.
127.0.0.2
127.0.0.1
10.10.10.1
To sort it, you can use the following command
# sort -t. -k1,1n -k2,2n -k3,3n -k4,4n ip.txt
10.10.10.1
127.0.0.1
127.0.0.2
source: http://www.linuxask.com/questions/how-to-sort-ip-addresses-in-linux