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
Script HW/SW AIX
Viewed 9089 times since Mon, Jun 4, 2018
The Ultimate Bash Array Tutorial with 15 Examples
Viewed 13222 times since Sun, Sep 30, 2018
“Yes/No” in Bash Script – Prompt for Confirmation
Viewed 31620 times since Mon, Feb 18, 2019
Linux: Repeat Command N Times – Bash FOR Loop
Viewed 2924 times since Mon, Feb 18, 2019
Display basic information about Physical Volumes
Viewed 3346 times since Sun, Jun 3, 2018
Time conversion using Bash
Viewed 2645 times since Fri, May 25, 2018
Utilities to Tidy Up Your Reports
Viewed 16206 times since Wed, May 30, 2018
Tunneling With SSH to Your Destination
Viewed 4250 times since Wed, May 30, 2018
awk printf
Viewed 14954 times since Wed, Aug 19, 2020
Bash: String Length – How To Find Out
Viewed 2152 times since Mon, Feb 18, 2019