How to sort IP addresses in Linux


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


Article Number: 42
Posted: Thu, May 24, 2018 8:15 PM
Last Updated: Thu, May 24, 2018 8:15 PM

Online URL: http://kb.ictbanking.net/article.php?id=42