I wanted to ask a question following up on the one I posted before:
awk compare columns from two files, impute values of another column
I am trying to figure out how I can print NA
when I have several unmatched values.
File1
rs1 AA 10
rs2 BB 20
rs3 CC 30
rs4 DD 40
File2
rs1 QQ TT UU
rs3 RR WW
rs4 ZZ
Desired output
rs1 AA 10 QQ TT UU
rs2 DD 20 NA NA NA
rs3 EE 30 RR WW NA
rs4 RR 40 ZZ NA NA
This code prints NA
only when the entire $0
is missing:
awk 'FNR==NR{a[$1]=$0;next}{print $0,a[$1]?a[$1]:"NA"}' file2 file1
Current output:
rs1 AA 10 QQ TT UU
rs2 DD 20 NA
rs3 EE 30 RR WW
rs4 RR 40 ZZ