Match

Trying to match $1 in output.txt with $1 probe.txt, when a match is found in $6 of probe.txt the text in $5 of output is copied.

For example, the first record in output.txt is A_16_P32713632 and that matches row 19318 in probe.txt, so in the 6 field (after 0.940798) of row 19318 ACTA2 is copied (that is the text in $5 of output). 

Thank you :).

I attached the files as well :).

What have you tried so far?

 awk 'BEGIN{OFS=FS=","}NR==FNR{a[$1$2];next}$5$6 in a{print $1,$2,$3,$4,$5,$6}' output.txt probe.txt > match.txt 

I am learning awk so not really sure the best solution. Thanks :).

Modified only the matches:

awk 'FNR==NR {A[$1]=$5; next} {print $0, A[$1]}' output.txt probe.txt > result.txt

or if you just want to keep the matches:

awk 'FNR==NR {A[$1]=$5; next} ($1 in A){print $0 A[$1]}' output.txt probe.txt > result.txt
1 Like

Thank you :).