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
LOGROTATE – ARCHIWIAZACJA LOGÓW
Viewed 2138 times since Fri, Nov 30, 2018
How To Ping Specific Port Number
Viewed 4537 times since Mon, Jun 1, 2020
Method 2 – Use shell scripts How to install yum cron on a CentOS/RHEL 6.x/7.x
Viewed 4289 times since Tue, Dec 4, 2018
RHEL: Back-up/Replicate a partition table
Viewed 3649 times since Sun, May 27, 2018
Jak ustawić LVM, jak robić snapshoty oraz automatycznie powiększać LV, czyli małe howto
Viewed 4803 times since Sun, May 20, 2018
SSH ProxyCommand example: Going through one host to reach another server
Viewed 13833 times since Tue, Aug 6, 2019
Using Official Redhat DVD as repository
Viewed 11344 times since Mon, Oct 29, 2018
RHEL: Handling SCSI disks
Viewed 12645 times since Sun, May 27, 2018
RHCS: Install a two-node basic cluster
Viewed 10192 times since Sun, Jun 3, 2018
Enabling automatic updates in Centos 7 and RHEL 7
Viewed 2624 times since Wed, Oct 17, 2018