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
Attachments
There are no attachments for this article.
Related Articles RSS Feed
RHCS6: Show/Add GFS2/GFS journals
Viewed 11279 times since Sun, Jun 3, 2018
How to clear swap memory in Linux
Viewed 640 times since Mon, Nov 23, 2020
RHEL: Extending a vmdk (Virtual Machine disk)
Viewed 2234 times since Sun, May 27, 2018
debian How to check Debian CVE status using python script
Viewed 1185 times since Sun, Sep 23, 2018
LVM: Managing snapshots
Viewed 5451 times since Sat, Jun 2, 2018
What UUIDs can do for you
Viewed 816 times since Tue, Jul 17, 2018
sed Delete / Remove ^M Carriage Return (Line Feed / CRLF) on Linux or Unix
Viewed 6856 times since Thu, Feb 7, 2019
Red Hat Cluster Tutorial
Viewed 1135 times since Sun, Jun 3, 2018
bash mistakes This page is a compilation of common mistakes made by bash users. Each example is flawed in some way.
Viewed 7339 times since Sun, Dec 6, 2020
Linux: Disks diagnostic using smartctl
Viewed 11992 times since Wed, Jul 25, 2018