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
Time conversion using Bash
Viewed 3658 times since Fri, May 25, 2018
8 Practical Examples of Linux Xargs Command for Beginners
Viewed 6825 times since Fri, Jun 1, 2018
30 Handy Bash Shell Aliases For Linux / Unix / MacOS
Viewed 6471 times since Thu, Feb 11, 2021
Epoch & Unix Timestamp Conversion Tools
Viewed 84967 times since Fri, Jun 22, 2018
Dealing with Funny Files
Viewed 3648 times since Wed, May 30, 2018
10 Awk Tips, Tricks and Pitfalls
Viewed 6918 times since Wed, Aug 19, 2020
Using Shell Redirection: All About the Here-Doc
Viewed 11633 times since Wed, May 30, 2018
O’Reilly’s CD bookshelf
Viewed 15719 times since Wed, Jun 27, 2018
Display basic information about Physical Volumes
Viewed 4530 times since Sun, Jun 3, 2018
Bash: String Length – How To Find Out
Viewed 3150 times since Mon, Feb 18, 2019