0

I have a file like this: (has 308545 lines)

head output11.bim
1   1:775852:T:C    0   775852  T   C
1   1:1120590:A:C   0   1120590 C   A
1   1:1145994:T:C   0   1145994 C   T
1   1:1148494:A:G   0   1148494 A   G
1   1:1201155:C:T   0   1201155 T   C
1   1:1468016:T:C   0   1468016 C   T
...

And another file (marker-info) which has the first 24 commented lines and is comma separated that looks like this (has total of 500593 lines):

1,742429,SNP_A-1909444,ss66079302,rs3094315,36.2,G,A,C,T,A,GCACAGCAAGAGAAAC[A/G]TTTGACAGAGAATACA,Sty,+,-,y,,,127,phs000018
1,769185,SNP_A-4303947,ss66273559,rs4040617,36.2,A,G,A,G,A,GCTGTGAGAGAGAACA[A/G]TGTCCCAATTTTGCCC,Sty,+,+,n,,,127,phs000018
1,775852,SNP_A-1886933,ss66317030,rs2980300,36.2,T,C,A,G,A,GAATGACTGTGTCTCT[C/T]TGAGTTAGTGAAGTCA,Nsp,-,+,y,,,127,phs000018
1,782343,SNP_A-2236359,ss66185183,rs2905036,36.2,C,T,C,T,A,CTCGATTTGTGTTCAA[C/T]ATATTTCATTTGTACC,Sty,-,-,n,,,127,phs000018
1,1120590,SNP_A-2205441,ss66174584,rs4245756,36.2,C,T,C,T,A,CCAGTGCTTTCAACCA[C/T]ACTCACTTTTCACTGT,Sty,+,+,n,,,127,phs000018
...

I want to replace in output11.bim second column with the 5th column in marker-info that has the matching value in 1st and 2nd column so for this example the result of the output11.bim would look like this:

1   rs2980300   0   775852  T   C
1   rs4245756   0   1120590 C   A

1 Answer 1

1
$ cat tst.awk
NR==FNR { map[$1,$2]=$5; next }
($1,$4) in map { $2=map[$1,$4]; print }

$ awk -f tst.awk FS=',' marker-info FS=' ' output11.bim
1 rs2980300 0 775852 T C
1 rs4245756 0 1120590 C A

or if you prefer to set FS to the 2 separate values within the script:

$ cat tst.awk
BEGIN { FS="," }
NR==FNR { map[$1,$2]=$5; next }
FNR==1 { FS=" "; $0=$0 }
($1,$4) in map { $2=map[$1,$4]; print }

$ awk -f tst.awk marker-info output11.bim
1 rs2980300 0 775852 T C
1 rs4245756 0 1120590 C A
1
  • 1
    Fantastic! Thank you so much!!!
    – anamaria
    Mar 28, 2020 at 0:24

You must log in to answer this question.

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