I have two files. First, I want to look at the column "Variant_Type" in the first file. If it is DEL, then I should look if there is a match between three columns in two files (Chromosome, vcf_pos, Reference_Allele) and append AC and AF columns from the first file to the second file. If it is INS in a "Variant_Type", then I look for the match between another three columns in the two files (Chromosome, vcf_pos, Tumor_Seq_Allele2) and append relevant AC and AF columns from the second file. If it is SNP, then again look for the match between another three columns in the two files (Chromosome, vcf_pos, Tumor_Seq_Allele2) and append relevant AC and AF columns from the second file.
Here is the snippet from File 1
Hugo_Symbol Chromosome Start_Position End_Position Reference_Allele Tumor_Seq_Allele2 Variant_Type vcf_pos
TMEM80 chr11 704605 704605 A - DEL 704604
OR52P1P chr11 5726537 5726537 T - DEL 5726536
UBTFL1 chr11 90086720 90086721 - T INS 90086720
DCPS chr11 126306583 126306584 - TGGGGA INS 126306583
DCPS chr11 126306583 126306584 - TGGGGAAA INS 126306583
File 2
Chromosome vcf_pos AF AC Reference_Allele Tumor_Seq_Allele2
chr11 704604 0.2 10 A -
chr11 5726536 0.35 13 T -
chr11 90086720 0.25 16 - T
chr11 126306583 0.5 29 - TGGGGA
chr11 126306583 0.3 39 - TGGGGAAA
Desired output
Hugo_Symbol Chromosome Start_Position End_Position Reference_Allele Tumor_Seq_Allele2 Variant_Type vcf_pos AF AC
TMEM80 chr11 704605 704605 A - DEL 704604 0.2 10
OR52P1P chr11 5726537 5726537 T - DEL 5726536 0.35 13
UBTFL1 chr11 90086720 90086721 - T INS 90086720 0.25 16
DCPS chr11 126306583 126306584 - TGGGGA INS 126306583 0.5 29
DCPS chr11 126306583 126306584 - TGGGGAAA INS 126306583 0.3 39
As a possible solution I was thinking about merge function in R, but might work better with awk