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 9383 times since Mon, Jun 4, 2018
Bash: String Length – How To Find Out
Viewed 2329 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
perl podstawy
Viewed 2135 times since Mon, May 21, 2018
Bash: Read File Line By Line – While Read Line Loop
Viewed 2379 times since Mon, Feb 18, 2019
30 Handy Bash Shell Aliases For Linux / Unix / MacOS
Viewed 5024 times since Thu, Feb 11, 2021
Transform XML to CSV Format | Unix String Pattern Manipulation The Ugly Way
Viewed 5921 times since Sun, Jan 9, 2022
8 Practical Examples of Linux Xargs Command for Beginners
Viewed 5663 times since Fri, Jun 1, 2018
Using Shell Redirection: All About the Here-Doc
Viewed 10564 times since Wed, May 30, 2018
Usuwanie spacji z zmiennych w bash
Viewed 2594 times since Tue, May 22, 2018