python - Using awk to compare and print output from both files -


is possible use awk compare , return results both files match?

i using:

awk 'begin{fs=ofs="\t"} nr==fnr{c[$1$2]++;next};c{$1$2}>0' queryfile hitsfile 

to match results query , return outputs in hits, returns columns hits files

i've tried:

awk 'begin{fs=ofs="\t"} nr==fnr{c[$1$2]++;next};c{$1$2}>0 {print $1,$2,c[$1]}' 

but doesnt work

my example data looks this:

queryfile

chr1 1000 1005 bdsd chr1 1010 1015 skk1 chr2 1015 1015 avpr 

hitsfile

chr1 1000 1005 0.5 chr1 1001 1002 0.35 chr1 1010 1015 0.4 chr1 1011 1016 0.56 chr2 1015 1015 0.1 

i output file following

*output results*  chr1 1000 1005 0.5 bdsd chr1 1010 1015 0.4 skk1 chr2 1015 1015 0.1 avpr 

so basically, hits match query returned plus column in query data. possible using awk oneliners?

also, question is possible given query range inside query file, , return lines within hitsfile compared exact matches awk?

usually these in r, slow when processing large files , awk much faster!

thank you!

$ awk 'nr==fnr{a[$1,$2]=$4;next} ($1,$2) in a{print $0, a[$1,$2]}' queryfile hitsfile chr1 1000 1005 0.5 bdsd chr1 1010 1015 0.4 skk1 chr2 1015 1015 0.1 avpr