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
Script to Offline and Remove A Disk In Linux
Viewed 2758 times since Mon, Jan 28, 2019
Testing TLS/SSL encryption
Viewed 14532 times since Thu, Jan 16, 2020
Creating SWAP partition using FDISK & FALLOCATE commands
Viewed 8383 times since Thu, Jan 16, 2020
Learn how to align an SSD on Linux
Viewed 14833 times since Fri, May 15, 2020
RHEL: Displaying system info (firmware, serial numbers... )
Viewed 13774 times since Sun, May 27, 2018
How to Configure ‘FirewallD’ in RHEL/CentOS 7 and Fedora 21
Viewed 12194 times since Wed, Oct 9, 2019
How setting the TZ environment variable avoids thousands of system calls
Viewed 11283 times since Mon, May 21, 2018
YUM CRON Enabling automatic updates in Centos 7 and RHEL 7
Viewed 13015 times since Fri, Oct 26, 2018
Linux – How to check the exit status of several piped commands
Viewed 3883 times since Wed, Jul 25, 2018
SSH Essentials: Working with SSH Servers, Clients, and Keys
Viewed 6007 times since Wed, Jun 27, 2018