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
Using Shell Redirection: All About the Here-Doc
Viewed 10496 times since Wed, May 30, 2018
HowTo: Clear BASH History
Viewed 2240 times since Mon, Feb 18, 2019
30 Handy Bash Shell Aliases For Linux / Unix / MacOS
Viewed 4909 times since Thu, Feb 11, 2021
8 Practical Examples of Linux Xargs Command for Beginners
Viewed 5607 times since Fri, Jun 1, 2018
Time conversion using Bash
Viewed 2790 times since Fri, May 25, 2018
10 Xargs Command Examples in Linux / UNIX
Viewed 4020 times since Fri, Jun 1, 2018
“Yes/No” in Bash Script – Prompt for Confirmation
Viewed 32806 times since Mon, Feb 18, 2019
The Ultimate Bash Array Tutorial with 15 Examples
Viewed 13519 times since Sun, Sep 30, 2018
awk printf
Viewed 15358 times since Wed, Aug 19, 2020
Tunneling With SSH to Your Destination
Viewed 4521 times since Wed, May 30, 2018