0

I have a file like this:

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
...

And another file:

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
...

What I want to get is changed cleandata.map which would look like this:

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
...

So if the row in 2nd column of lifted.map is matching the row of the 2nd column of cleandata.map replace the row in 2nd and 4th column and of cleandata.map with the value of 4th column in the lifted.map.

4
  • What do you need cleandata for? It looks as if you could build the final file with just the information in lifted.map. By the way, could you share what you've tried so far? Apr 2, 2020 at 2:33
  • I need my file cleandata.map to change those positions so that I can perform soem Plink analysis on it, so there I am changing positions of SNPs. I don't really know how to start with this...sorry
    – anamaria
    Apr 2, 2020 at 2:36
  • If you take just lifted.map and replace the long number on the left with the one on the right (keeping the 1:nnnn:X:Y, would that do it? Apr 2, 2020 at 2:46
  • take a look to this [post][1] [1]: stackoverflow.com/questions/18592736/… Apr 2, 2020 at 2:47

1 Answer 1

0

Try

$ 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
1
  • Thank you so much!
    – anamaria
    Apr 2, 2020 at 12:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .