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
4 (1)
Article Rating (1 Votes)
Rate this article
Attachments
There are no attachments for this article.
Comments
There are no comments for this article. Be the first to post a comment.
Full Name
Email Address
Security Code Security Code
Related Articles RSS Feed
Display basic information about Physical Volumes
Viewed 4409 times since Sun, Jun 3, 2018
Using Shell Redirection: All About the Here-Doc
Viewed 11552 times since Wed, May 30, 2018
Linux and Unix xargs command tutorial with examples
Viewed 4588 times since Fri, Jun 1, 2018
awk printf
Viewed 17304 times since Wed, Aug 19, 2020
View Config Files Without Comments
Viewed 3009 times since Mon, May 21, 2018
Convert a human readable date to epoch with a shell script on OpenBSD and Mac OS X
Viewed 16164 times since Fri, May 25, 2018
10 Awk Tips, Tricks and Pitfalls
Viewed 6829 times since Wed, Aug 19, 2020
Utilities to Tidy Up Your Reports
Viewed 17075 times since Wed, May 30, 2018
10 Xargs Command Examples in Linux / UNIX
Viewed 4899 times since Fri, Jun 1, 2018
Adding a range of IPs in Linux
Viewed 3456 times since Mon, May 21, 2018