regex - Compare fields in line against each other -


i have file per below;

             env_ab 1.1.11.0              env_bb 1.1.11.0              env_cc 1.1.11.0              env_dd 1.1.11.0              env_ff 1.1.11.0              env_gg 1.1.11.0              env1_ab 1.1.11.0              env1_bb 1.1.10.0              env1_cc 1.1.11.0              env1_dd 1.1.11.0              env1_ff 1.1.11.0              env1_gg 1.1.11.0 

- can seen, each env there 6 version numbers. - want do, compare 6 version number each env. - so, env_(ab,bb,cc..etc) has 6 versions (1.1.11.0), want able compare env_ab,bb,cc,dd,ff,gg 1 , if same print 1 env , version. if not same, print out not same & print once env same version.

expected output above if envs file same;

          env_ab 1.1.11.0           env1_ab 1.1.11.0 

however there diffrenet version in 1 of env (so change env_bb version 1.1.10.0), expected output be; env_ab 1.1.11.0 env_bb 1.1.10.0 env1_ab 1.1.11.0 feasible? have researched associative arrays not seem resolution this.

if understand trying do, this:

  1. take file pattern of key_dk version defines group , dk ignored
  2. print first line , line of group.

in awk can do:

$ awk '{split($1, x, "_")          if (a[x[1], $2]) next          a[x[1], $2]=$1 ofs $2 }         end{ (i in a) print a[i]}' file env1_ab 1.1.11.0 env_ab 1.1.11.0 env1_bb 1.1.10.0 

the order printed not same file order since associative arrays unordered in awk. if want output same file order, loop through file twice.


Comments

Popular posts from this blog

What is happening when Matlab is starting a "parallel pool"? -

angular - DownloadURL return null in below code -

php - Cannot override Laravel Spark authentication with own implementation -