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
FIO (Flexible I/O) – a benchmark tool for any operating system
Viewed 19485 times since Wed, Jul 25, 2018
OCFS2 Cluster File System Setup Guide in Linux
Viewed 7226 times since Sat, Jun 2, 2018
RHEL: Enabling standard ftp/telnet
Viewed 3508 times since Sun, May 27, 2018
LVM: Extend an existing Logical Volume / Filesystem
Viewed 2507 times since Sat, Jun 2, 2018
Using grep to find string in files
Viewed 2241 times since Fri, May 15, 2020
RHEL: Change system’s hostname
Viewed 3543 times since Sun, May 27, 2018
RHCS6: Mirror/unmirror a GFS2 volume
Viewed 5275 times since Sun, Jun 3, 2018
Linux – How to check the exit status of several piped commands
Viewed 2979 times since Wed, Jul 25, 2018
List DNS records, nameservers of a domain from command line
Viewed 2021 times since Sun, Sep 30, 2018
RHEL: Reserved space on a ext2/ext3/ext4 filesystem
Viewed 4509 times since Sun, May 27, 2018