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
Open SSL Creating Certificate Signing Request — CSR Generation
Viewed 1815 times since Mon, Feb 18, 2019
What is OS Watcher Utility and How to use it for Database Troubleshooting ?
Viewed 29938 times since Thu, Jun 21, 2018
YUM CRON Enabling automatic updates in Centos 7 and RHEL 7
Viewed 11834 times since Fri, Oct 26, 2018
SSH: Execute Remote Command or Script – Linux
Viewed 2303 times since Mon, Feb 18, 2019
LVM: Recovering Physical Volume Metadata
Viewed 13043 times since Sat, Jun 2, 2018
Terminal based "The Matrix" like implementation
Viewed 2121 times since Thu, Apr 18, 2019
List usernames instead of uids with the ps command for long usernames
Viewed 2271 times since Wed, Jul 25, 2018
ZPOOL: Remove an existing zpool
Viewed 2215 times since Sun, Jun 3, 2018
Red Hat 8 How to Set Up Automatic Updates for CentOS 8
Viewed 3588 times since Fri, Sep 25, 2020
LVM: Reduce SWAP size by shrinking existing Logical Volume
Viewed 6087 times since Sat, Jun 2, 2018