Como substituir uma string correspondente em um arquivo pela string correspondente em outro arquivo?

Como substituir uma string correspondente em um arquivo pela string correspondente em outro arquivo?

Eu tenho um arquivo como este:

head cleandata.map
1   1:775852:T:C    0   775852
1   1:1120590:A:C   0   1120590
1   1:1145994:T:C   0   1145994
1   1:1148494:A:G   0   1148494
...

E outro arquivo:

head lifted.map
1   1:775852:T:C    0.0 785989
1   1:1120590:A:C   0.0 1130727
1   1:1145994:T:C   0.0 1156131
1   1:1148494:A:G   0.0 1158631
...

O que eu quero é alterar cleandata.map, que ficaria assim:

1   1:785989:T:C    0   785989
1   1:1130727:A:C   0   1130727
1   1:1156131:T:C   0   1156131
1   1:1158631:A:G   0   1158631
...

Portanto, se a linha na 2ª coluna de lifted.map corresponder à linha da 2ª coluna de cleandata.map, substitua a linha na 2ª e 4ª coluna e de cleandata.map pelo valor da 4ª coluna em lift.map.

Responder1

Tentar

$ awk 'FNR==NR {T[$2] = $4; next} $2 in T {gsub ($4, T[$2])} 1' file2 file1
1   1:785989:T:C    0   785989
1   1:1130727:A:C   0   1130727
1   1:1156131:T:C   0   1156131
1   1:1158631:A:G   0   1158631

informação relacionada