Awk 从两个格式不同的文件中打印符合条件的行

Awk 从两个格式不同的文件中打印符合条件的行,awk,Awk,我正在尝试打印file1中与file2匹配的行$1具有存储在数组c中的值,然后在file2$1:$2。这是用于匹配行的第一个标准,但不是唯一的标准

我正在尝试打印
file1
中与
file2
匹配的行<
file1
中的code>$1具有存储在数组c中的值,然后在
file2
$1
$2
。这是用于匹配行的第一个标准,但不是唯一的标准<如果满足这两个标准,
file1
中的
$5
必须与
file2
中的
$4
匹配,并且
file1
中的
$2
SNV或INDEL
$3
file1
exonic
时,打印
file1
中的匹配行。如果行不匹配,则跳过它们。下面的
awk
执行,但没有输出结果,在本例中,应该有一行。我的实际数据是几千行,都是下面的格式。谢谢:)

文件1

##reference=hg19
##referenceURI=hg19
# locus type    location    function    coding

chr1:11184539   CNV
chr1:11184573   REF exonic
chr1:11189845   REF exonic
chr2:47630550   SNV intronic
chr4:55141050   SNV exonic  synonymous  c.1701A>G
chr4:55141050   INDEL   exonic  nonsynonymous    c.1697_1711delGCCCAGATGGACATG
文件2

chr4    55141050    COSM742     c.1696_1713delAGCCCAGATGGACATGAAinsCGC  p.Ser566_Glu571delinsArg
chr4    55141050    COSM12417   c.1697_1711delGCCCAGATGGACATG   p.Ser566_Glu571delinsLy
awk

awk 'FNR==3 {next}
  # skip first three lines in file1   
             {FS = OFS = "\t"}
  # define input and output as tab-delimited         
               NR==FNR{c[$1]; next} ($1":"$2) in c && NR==FNR{c[$5];next}$4 in c && $2 ~ /SNV|INDEL/ && $3=="exonic"' file1 file2
 # process each line in file matching on criteria
所需输出

chr4:55141050   INDEL   exonic  synonymous  c.1697_1711delGCCCAGATGGACATG

Awk
解决方案:

awk 'NR==FNR{ a[$1":"$2]=substr($4,1,6); next }
     NF>=5 && $2~/SNV|INDEL/ && $3=="exonic" &&
     ($1 in a) && a[$1]==substr($5,1,6)' file2 OFS='\t' file1
输出:

chr4:55141050   INDEL   exonic  nonsynonymous    c.1697_1711delGCCCAGATGGACATG