Sorting ip Addresses in Numerical Order Bash

Here’s how you could order ip address in numerical order, sorting by each octect individually. Let’s say you have a file containing the following ips.

jorge@laptopNix$ cat address

to sort them….

jorge@laptopNix$ sort address -n -k1,1 -k2,2 -k3,3 -k4,4

where -n tells to do a numeric sort and -k to start sorting at first field and end at first. Just repeat the process for every octect. Of course if you have a file containing class C only address you only would have to use -k4,4

Share This!

Add a Comment

Your email address will not be published.

Sign up for our Newsletter

Download "Google Search Pro"

Enter your email and stay on top of things,