vendredi 19 février 2016

If column match with value, use gsub and print value to another column

I use some example:

INPUT:

0.6     0.7    A:0.01   -       0
C:0.01  0.1    -        0.2     0
0.7     0.02   G:0.2    -       0
0.5     0.23   0.1      T:0.05  0
0.1     0.2    0.3      0.58    0

So, if some column has a value start with A C T or G I would like to change it to "0" or "-" and last column change to "W" (it is $34 $35 $36 $37 $38 )

OUTPUT:

0.6     0.7    0        -       W
0       0.1    -        0.2     W
0.7     0.02   0        -       W
0.5     0.23   0.1      0       W
0.1     0.2    0.3      0.58    0 

I would like to use awk.

awk '{if($34=="^:^");gsub($34,"*","0") && gsub($38,"0","W"); else print}' file

and same for other columns. Thank you.

Aucun commentaire:

Enregistrer un commentaire