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 1990 times since Sun, Jun 3, 2018
Kernel sysctl configuration file for Linux
Viewed 5003 times since Fri, Aug 3, 2018
CentOS / RHEL : Configure yum automatic updates with yum-cron service
Viewed 3407 times since Fri, Oct 26, 2018
Moving SSL Certificate from IIS to Apache
Viewed 1825 times since Mon, Feb 18, 2019
Netcat shell zabezpieczony hasłem
Viewed 2046 times since Thu, May 24, 2018
ZPOOL: Add a mirror to a concat zpool
Viewed 3592 times since Sun, Jun 3, 2018
Tcpdump Examples Linux
Viewed 5704 times since Fri, Nov 16, 2018
Logrotate Example for Custom Logs
Viewed 2403 times since Sun, Jan 12, 2020
Sample logrotate configuration and troubleshooting part 2
Viewed 9308 times since Fri, Nov 30, 2018
Managing temporary files with systemd-tmpfiles on Red Hat Enterprise Linux 7
Viewed 9351 times since Sun, Nov 22, 2020