I have a .bim file with variant identifier as chr:pos and a SNPs list.file matching chr:pos and rs IDs.
file1 (the .bim file):
1 1:10583 0 10583 G A
1 1:10611 0 10611 G C
...
22 22:51242613 0 51242613 C A
22 22:51243297 0 51243297 T A
file2 (SNP list):
rs99999 4:163870478
rs99998 4:117161848
...
when column2 in file1 matches with column2 in file2 (both are chr:pos), I want to replace column2 in file1 with column1 in file2, otherwise, keep column2 in file1.
I tried the following script but didn't work, no replacement happened. Anyone can kindly help?
awk -F"\t" -v OFS="\t" '{
if (FNR==NR) {
a[FNR]=$2;b[FNR]=$1}
else {
if (a[FNR] == $2) {
$2=b[FNR]} else {$2=$2};
print $0
}
}' file2 file1 > file1_update