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
O’Reilly’s CD bookshelf
Viewed 15831 times since Wed, Jun 27, 2018
30 Handy Bash Shell Aliases For Linux / Unix / MacOS
Viewed 6536 times since Thu, Feb 11, 2021
Bash: String Length – How To Find Out
Viewed 3235 times since Mon, Feb 18, 2019
Transform XML to CSV Format | Unix String Pattern Manipulation The Ugly Way
Viewed 8559 times since Sun, Jan 9, 2022
Time conversion using Bash
Viewed 3732 times since Fri, May 25, 2018
Linux: Repeat Command N Times – Bash FOR Loop
Viewed 4152 times since Mon, Feb 18, 2019
perl podstawy
Viewed 2689 times since Mon, May 21, 2018
View Config Files Without Comments
Viewed 3091 times since Mon, May 21, 2018
Convert a human readable date to epoch with a shell script on OpenBSD and Mac OS X
Viewed 16305 times since Fri, May 25, 2018
Utilities to Tidy Up Your Reports
Viewed 17234 times since Wed, May 30, 2018