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
RHCS6: Show/Add GFS2/GFS journals
Viewed 12416 times since Sun, Jun 3, 2018
How to enable automatic security updates on CentOS 7 with yum-cron
Viewed 2232 times since Fri, Oct 26, 2018
How To Use Systemctl to Manage Systemd Services and Units
Viewed 7080 times since Mon, Dec 7, 2020
LVM: Extend an existing Volume Group by adding a new disk
Viewed 1778 times since Sat, Jun 2, 2018
Inxi – A Powerful Feature-Rich Commandline System Information Tool for Linux
Viewed 18679 times since Sat, Jun 2, 2018
What UUIDs can do for you
Viewed 1555 times since Tue, Jul 17, 2018
LVM: Extend an existing Logical Volume / Filesystem
Viewed 2155 times since Sat, Jun 2, 2018
Linux – Securing your important files with XFS extendend attributes
Viewed 7308 times since Wed, Jul 25, 2018
Linux RAID Mdadm Cheat Sheet
Viewed 4906 times since Fri, May 15, 2020
how to list all hard disks in linux from command line
Viewed 2848 times since Mon, Jan 28, 2019