Home > Software engineering >  sort lines by one colum and then by column with IP addresses
sort lines by one colum and then by column with IP addresses

Time:02-17

input list is:

10.190.30.41    ENV-DEFAPP-T01
10.190.30.9     ENV-UATDB-T01
10.190.30.38    ENV-DEFDB-T01
10.190.30.36    ENV-DEFDB-T01
10.190.30.10    ENV-UATDB-T01
10.190.30.133   ENV-DEFDB-T01
10.190.30.37    ENV-DEFDB-T01
10.190.30.40    ENV-DEFAPP-T01
10.190.30.39    ENV-DEFDB-T01
10.190.30.37    ENV-GHIAPP-T01
10.190.30.132   ENV-DEFDB-T01
10.190.30.40    ENV-DEFDB-T01
10.190.31.7     ENV-GHIAP-T01
10.190.31.7     ENV-DEFDB-T01
10.190.30.132   ENV-DEFAPP-T01
10.190.30.41    ENV-DEFDB-T01
10.190.30.36    ENV-GHIMO-T01
10.190.30.42    ENV-UATNFS-T01
10.190.30.39    ENV-DEFAPP-T01
10.190.30.133   ENV-GHIAPP-T01
10.190.30.36    ENV-DEFAPP-T01
10.190.31.8     ENV-GHIDB-T01
10.190.30.38    ENV-GHIAPP-T01

I want to sort it with GNU sed in first step by column #2 and theby column #1 (IP addresses).

When I sort with -k2 -k1 first column is not sorted properly (by incremental IPs in each ENV):

$ cat input|tr -s ' '|sort -k2 -k1|column -ts" " --
10.190.30.132  ENV-DEFAPP-T01
10.190.30.36   ENV-DEFAPP-T01
10.190.30.39   ENV-DEFAPP-T01
10.190.30.40   ENV-DEFAPP-T01
10.190.30.41   ENV-DEFAPP-T01
10.190.30.132  ENV-DEFDB-T01
10.190.30.133  ENV-DEFDB-T01
10.190.30.36   ENV-DEFDB-T01
10.190.30.37   ENV-DEFDB-T01
10.190.30.38   ENV-DEFDB-T01
10.190.30.39   ENV-DEFDB-T01
10.190.30.40   ENV-DEFDB-T01
10.190.30.41   ENV-DEFDB-T01
10.190.31.7    ENV-DEFDB-T01
10.190.30.133  ENV-GHIAPP-T01
10.190.30.37   ENV-GHIAPP-T01
10.190.30.38   ENV-GHIAPP-T01
10.190.31.7    ENV-GHIAP-T01
10.190.31.8    ENV-GHIDB-T01
10.190.30.36   ENV-GHIMO-T01
10.190.30.10   ENV-UATDB-T01
10.190.30.9    ENV-UATDB-T01
10.190.30.42   ENV-UATNFS-T01

CodePudding user response:

Sort the IP address as a "version"

sort -k2 -k1V
  • Related