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
Applescript: Run or Call a Shell Script
Viewed 4299 times since Tue, Aug 6, 2019
Jak znaleźć najszybszy publiczny serwer DNS w Polsce?
Viewed 3173 times since Mon, May 21, 2018
LVM: Extend an existing Logical Volume / Filesystem
Viewed 2577 times since Sat, Jun 2, 2018
Procedura powiekszania OCFS2 online
Viewed 5512 times since Fri, Jun 8, 2018
RHCS6: Show/Add GFS2/GFS journals
Viewed 12821 times since Sun, Jun 3, 2018
ZPOOL: Add a mirror to a concat zpool
Viewed 3884 times since Sun, Jun 3, 2018
Enabling automatic updates in Centos 7 and RHEL 7
Viewed 2575 times since Wed, Oct 17, 2018
How to configure an SSH proxy server with Squid
Viewed 3205 times since Sun, Dec 6, 2020
logrotate Understanding logrotate utility
Viewed 1878 times since Sun, Jan 12, 2020
Creating SWAP partition using FDISK & FALLOCATE commands
Viewed 3557 times since Thu, Jan 16, 2020