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
Enabling automatic updates in Centos 7 and RHEL 7
Viewed 2394 times since Wed, Oct 17, 2018
YUM CRON Enabling automatic updates in Centos 7 and RHEL 7
Viewed 11834 times since Fri, Oct 26, 2018
10 Linux cryptsetup Examples for LUKS Key Management (How to Add, Remove, Change, Reset LUKS encryption Key)
Viewed 5043 times since Tue, Jul 31, 2018
Fedora 32: Simple Local File-Sharing with Samba CIFS Linux
Viewed 8694 times since Sun, Dec 6, 2020
Configuring VLAN interfaces in Linux
Viewed 5340 times since Mon, May 21, 2018
socat: Linux / UNIX TCP Port Forwarder
Viewed 9452 times since Tue, Aug 6, 2019
How to Analyze or Read OS Watcher Output in three easy steps -- With Example ?
Viewed 41348 times since Thu, Jun 21, 2018
ubuntu How to reset lost root password on Ubuntu 16.04 Xenial Xerus Linux
Viewed 8156 times since Tue, Dec 8, 2020
RHCS6: Create a new Logical Volume / Global Filesystem 2 (GFS2)
Viewed 2154 times since Sun, Jun 3, 2018
Epoch & Unix Timestamp Conversion Tools
Viewed 61499 times since Fri, Jun 22, 2018