Lookup value of file1 in file2 using a key

Trying to use awk to match each line in file1 with line in file2 using $1 and $2 and print. File2 is tab-delimeted as is the output and if there is no match then it is skipped. The awk below executes but the output is empty. I think file1 is being split on the : and being saved in array c which looked-up in $1 and $2 of file2 . Thank you :).

file1 single column

chr12:25380271
chr12:25387855

file2 tab-delimeted

chr12	25380271	COSM27159	C	T	KRAS	NM_033360.3	exonic	c.187G>A	p.Glu63Lys
chr12	25380275	COSM555	T	A	KRAS	NM_033360.3	exonic	c.183A>T	p.Gln61His
chr12	25380275	COSM554	T	G	KRAS	NM_033360.3	exonic	c.183A>C	p.Gln61His

awk

awk -F':' 'NR==FNR{c[$1$2]++;next};c[$1$2] > 0' file1 file2

desired output

chr12	25380271	COSM27159	C	T	KRAS	NM_033360.3	exonic	c.187G>A	p.Glu63Lys
awk 'NR==FNR{c[$1]=$1;next} c[$1":"$2]' file1 FS="\t" file2
1 Like

You do not need to store any values in the array.
The lookup of the array index is done with in like this

awk 'NR==FNR{c[$1]; next} ($1":"$2) in c' file1 FS="\t" file2
1 Like

Thank you both very much :).