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
RHEL: Extending a vmdk (Virtual Machine disk)
Viewed 4370 times since Sun, May 27, 2018
Linux - How to get CPU information
Viewed 2396 times since Fri, Jun 8, 2018
How To Add Swap Space on Ubuntu 16.04
Viewed 2545 times since Fri, Jun 8, 2018
LVM: Reduce root PV/VG
Viewed 5391 times since Sat, Jun 2, 2018
Build a simple RPM that packages a single file
Viewed 8787 times since Sat, Jun 2, 2018
Kernel sysctl configuration file for Linux
Viewed 5489 times since Fri, Aug 3, 2018
LOGROTATE – ARCHIWIAZACJA LOGÓW
Viewed 2195 times since Fri, Nov 30, 2018
SPRAWDZONA KONFIGURACJA RSYSLOG I LOGROTATE, JAKO ZEWNĘTRZNEGO SERWERA SYSLOG
Viewed 4012 times since Fri, Nov 30, 2018
Linux – Securing your important files with XFS extendend attributes
Viewed 7703 times since Wed, Jul 25, 2018
Linux Chage Command to Set Password Aging for User
Viewed 2625 times since Tue, Sep 11, 2018