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
Linux - How to get IP and MAC address of ethernet adapter in Linux
Viewed 1159 times since Fri, Jun 8, 2018
Linux Find Large Files
Viewed 1324 times since Mon, Oct 29, 2018
RHEL: GPT/MBR partition tables (using disks larger than 2 TiB)
Viewed 10345 times since Sun, May 27, 2018
Get UUID of Hard Disks [Update]
Viewed 1178 times since Tue, Jul 17, 2018
Securing /tmp and shm partitions
Viewed 1158 times since Fri, May 15, 2020
Linux - How to perform I/O performance test with dd command
Viewed 4706 times since Fri, Jun 8, 2018
Fałszujemy rozpoznania skanerów #1
Viewed 1759 times since Mon, May 21, 2018
sed Delete / Remove ^M Carriage Return (Line Feed / CRLF) on Linux or Unix
Viewed 6856 times since Thu, Feb 7, 2019
logrotate How log rotation works with logrotate
Viewed 7712 times since Sun, Jan 12, 2020
OpenSSL: Check If Private Key Matches SSL Certificate & CSR
Viewed 1260 times since Mon, Feb 18, 2019