Can you describe how you arrive at this output? I imagine replace 3rd field of main.txt with 2nd field of code.txt, but your output shows 1 line and there are many matches for "CXP9014346/1_R6AG03"
I thought I did? NR is internal variable which holds the record number. So basically is the line number in this case. FNR is per-file, so if they're equal you're currently processing a line in the first file. the action { a[$1]=$2; next } first assigns an array using the first field as the key. the next means go on to the next line without further processing (skips the remaining print block).
so we're at the 2nd file and FNR==NR is no longer true. (imagine the first file is just 4 lines as your example, the first line in the second file FNR would be 1 while NR would continue to 5). In that case we check if the 3rd field matches any of the stored elements ($3 in a) and print...
The above script will give the print out all lines in file2 that 'match' with record in file1. Is possible to print unmatched line? expected print out for unmatched record as below example, if CXP9016868/1_R5G08 is not in the record: