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
ZFS: Remove an existing zfs filesystem
Viewed 2754 times since Sun, Jun 3, 2018
How to encrypt a partition with DM-Crypt LUKS on Linux
Viewed 8980 times since Fri, Jul 13, 2018
Red Hat Enterprise Linux - Allow Root Login From a Specific IP Address Only
Viewed 3564 times since Wed, Oct 3, 2018
RHEL: Retrieve and generate a unique SCSI identifier
Viewed 4145 times since Sat, Jun 2, 2018
Easily Monitor CPU Utilization in Linux Terminal With Stress Terminal UI
Viewed 5159 times since Thu, Apr 18, 2019
Improve security with polyinstantiation
Viewed 14419 times since Fri, May 15, 2020
How to disable SSH cipher/ MAC algorithms for Linux and Unix
Viewed 50765 times since Fri, Aug 21, 2020
Df command in Linux not updating actual diskspace, wrong data
Viewed 3551 times since Wed, May 30, 2018
HOWTO: Use SSL/port 465 in smarthost stunnel
Viewed 4581 times since Fri, Sep 28, 2018
RHCS6: ’fencing’ basics
Viewed 3034 times since Sun, Jun 3, 2018