Input file tab separated:A   |B   |  C | KEY  |  D|  E|  F  |G     | H | I | J   |   k |      ----|----|----|------|---|---|-----|------|---|---|-----|-----|      word|word|word| one  |  8|  8|qw123|    | | | word| word|      word|word|word| one  |  8|  8|qw234|    | | | word| word|      word|word|word| one  |  8|  8|qw111| er432| | | word| word|      word|word|word| seven|  8|  8|tr123|    | | | word| word|      word|word|word| seven|  8|  8|ww000|    | | | word| word|      Desired Output:                                                                     A   |B   |  C | KEY  |D |E |F    |G    |H    |I    |J   |K   |  ----|----|----|------|--|--|-----|-----|-----|-----|----|----|word|word|word|one   | 8| 8|qw123|qw234|qw111|er432|word|word|word|word|word|one   | 8| 8|qw123|qw234|qw111|er432|word|word|word|word|word|one   | 8| 8|qw123|qw234|qw111|er432|word|word|word|word|word|seven | 8| 8|tr123|ww000|   |   |word|word|word|word|word|seven | 8| 8|tr123|ww000|   |   |word|word|It is about merging the range of columns [F to I] with the same KEY.Is it possible to achieve this without using arrays in AWK? How I can control when the value of the key column changes?
Combine range of columns with the same key
bash;awk;gawk
I don't see how you could do this in Awk without using arrays. It would be more convenient in Gawk, which allows array elements to be arrays, but it's easy enough to do with ordinary Awk simulated-multidimensional arrays.Basically, we need to remember input lines and then output them (with the updated F-I fields) when the key changes. We need to also do that at the end of the file. For convenience, we use an output function since it will inevitably be called from two places.The following uses fixed column numbers: 1-6 and 11-12 for the standard data fields, with 4 being the key field, and 7-10 for the merged fields, which I called tags for want of a better name. That's not great style, and it should probably be factored out into some variables.awk -F '\t' '  function show_and_reset(            i, c) {    for (i = 1; i <= count; ++i) {      for (c = 1; c <= 6; ++c) printf %s\t, data[i,c]      for (f in tags) printf %s\t, f;      for (c = ntags; c <= 3; ++c) printf \t       for (c = 11; c <= 12; ++c) printf \t%s, data[i,c]      print     }    /* Clear the holding data */    for (f in tags) delete tags[f]    ntags = 0;    count = 0  }  /* Record one line of data */  function record(                   c) {    ++count;    for (c = 1; c <= 6; ++c) data[count,c] = $c    for (c = 11; c <= 12; ++c) data[count,c] = $c    for (c = 6; c <= 10; ++c)       if ($c !=  && !tags[$c]++) ++ntags;  }  $4 != key { show_and_reset(); key = $4; }            { record(); }  END       { show_and_reset(); }'