left join using awk

Hi guys,

I need to use awk to join 2 files

file_1
A 001
B 002
C 003

file_2
A XX1
B XX2

output desired
A 001 XX1
B 002 missing
C 003 XX2

thank you!

Didn't you mean that file_2 contains :

A XX1
C XX2

???

So it could be something like :

awk 'NR==FNR{A[$1]=$2;next}{print$0 FS (A[$1]?A[$1]:"missing")}' file_2 file_1

Otherwise i don't get the logic of your output

1 Like

Hi ctsgnb

I was wrong.. I meant

file_1
A 001
B 002
C 003

file_2
A XX1
B XX2

output desired
A 001 XX1
B 002 XX2
C 003 missing

anyway your awk script works! Thank you!