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
How to Clear RAM Memory Cache, Buffer and Swap Space on Linux
Viewed 1844 times since Mon, Nov 23, 2020
Find All Large Files On A Linux System
Viewed 1716 times since Mon, Oct 29, 2018
How to mount software RAID1 member using mdadm
Viewed 2658 times since Wed, Oct 3, 2018
LVM: Extend SWAP size by growing existing Logical Volume
Viewed 2119 times since Sat, Jun 2, 2018
SSH ProxyCommand example: Going through one host to reach another server
Viewed 12671 times since Tue, Aug 6, 2019
List of 10 Must Know Oracle Database Parameters for Database Administrator
Viewed 112444 times since Thu, Jun 21, 2018
Linux Health Check Commands
Viewed 2615 times since Fri, Jun 8, 2018
Learn Linux System Auditing with Auditd Tool on CentOS/RHEL
Viewed 3724 times since Fri, Apr 5, 2019
SSH: Execute Remote Command or Script – Linux
Viewed 1906 times since Mon, Feb 18, 2019
Red Hat Cluster Tutorial
Viewed 1712 times since Sun, Jun 3, 2018