Tuesday, August 12, 2014

Sort list of IP Addresses using LINUX/UNIX sort utility:


sort -t'.' -k 1,1 -k 2,2 -n -k 3,3 -k 4,4 1.txt

where
-t specifies field separator
-k specifies the field, on which sorting is happening

       -t, --field-separator=SEP
              use SEP instead of non-blank to blank transition

       -k, --key=POS1[,POS2]
              start a key at POS1, end it at POS2 (origin 1)


cat 1.txt
243.242.6.254
192.21.64.1
156.20.4.92
30.160.5.20
30.20.12.1
30.20.5.1



O/P;
30.20.5.1
30.20.12.1
30.160.5.20
156.20.4.92
192.21.64.1
243.242.6.254

No comments:

Post a Comment