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
View Config Files Without Comments
Viewed 2766 times since Mon, May 21, 2018
Bash: String Length – How To Find Out
Viewed 2698 times since Mon, Feb 18, 2019
Bash: Read File Line By Line – While Read Line Loop
Viewed 2841 times since Mon, Feb 18, 2019
Linux and Unix xargs command tutorial with examples
Viewed 4329 times since Fri, Jun 1, 2018
10 Xargs Command Examples in Linux / UNIX
Viewed 4585 times since Fri, Jun 1, 2018
Utilities to Tidy Up Your Reports
Viewed 16669 times since Wed, May 30, 2018
Tunneling With SSH to Your Destination
Viewed 5183 times since Wed, May 30, 2018
Linux: Repeat Command N Times – Bash FOR Loop
Viewed 3610 times since Mon, Feb 18, 2019
Transform XML to CSV Format | Unix String Pattern Manipulation The Ugly Way
Viewed 7391 times since Sun, Jan 9, 2022
perl podstawy
Viewed 2397 times since Mon, May 21, 2018