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
8 Vim Tips And Tricks That Will Make You A Pro User
Viewed 3704 times since Fri, Apr 19, 2019
logrotate How log rotation works with logrotate
Viewed 9730 times since Sun, Jan 12, 2020
How to find the largest files and directories in Linux?
Viewed 4013 times since Sun, May 20, 2018
RHCS6: Create a new Logical Volume / Global Filesystem 2 (GFS2)
Viewed 2970 times since Sun, Jun 3, 2018
How to Configure ‘FirewallD’ in RHEL/CentOS 7 and Fedora 21
Viewed 11344 times since Wed, Oct 9, 2019
OEL 7 – How to disable IPv6 on Oracle Linux 7 – Follow Up
Viewed 10193 times since Wed, Jul 25, 2018
LVM: Move allocated PE between Physical Volumes
Viewed 4711 times since Sat, Jun 2, 2018
Using etckeeper with git
Viewed 7623 times since Sun, Jun 3, 2018
ZPOOL: Detach a submirror from a mirrored zpool
Viewed 3329 times since Sun, Jun 3, 2018
LVM: Reduce SWAP size by removing a Logical Volume
Viewed 2640 times since Sat, Jun 2, 2018