There are two files I am going to extract the data:
file1.txt:
Type Number ID Element Email
Zed 21-2 9 Blade
file2.txt:
Name Order Email_Address
Ken 19 ken@gmail.com
Tom 21 tom@gmail.com
Ray 23 ray@gmail.com
How can I combine two files into a file with the following results:
Type Number ID Element Email
Zed 21-2 9 Blade tom@gmail.com
Here is what I have tried before:
awk 'NR==1{print $0;next} NR==FNR{a[$2]=$1"\t"$3"\t"$4";next} {if($2 in a){print(a[$2]"\t"$3)}}' file1.txt file2.txt
I think I cannot get the results because of the if statement there have some problem. How can I get the wanted results?