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
The Ultimate Bash Array Tutorial with 15 Examples
Viewed 13593 times since Sun, Sep 30, 2018
Transform XML to CSV Format | Unix String Pattern Manipulation The Ugly Way
Viewed 5920 times since Sun, Jan 9, 2022
Tunneling With SSH to Your Destination
Viewed 4587 times since Wed, May 30, 2018
“Yes/No” in Bash Script – Prompt for Confirmation
Viewed 33139 times since Mon, Feb 18, 2019
Epoch & Unix Timestamp Conversion Tools
Viewed 63260 times since Fri, Jun 22, 2018
View Config Files Without Comments
Viewed 2433 times since Mon, May 21, 2018
Display basic information about Physical Volumes
Viewed 3578 times since Sun, Jun 3, 2018
Dealing with Funny Files
Viewed 2884 times since Wed, May 30, 2018
Bash: Read File Line By Line – While Read Line Loop
Viewed 2378 times since Mon, Feb 18, 2019
How to get a password from a shell script without echoing - solutions
Viewed 14048 times since Fri, Feb 22, 2019