Hi,
I want to compare two files using awk and write an output based on if the records matched.
Both the files are space delimitted.
File A:
8351 00000000000636 2009044 -00001.000
8351 00000000000637 2009044 -00002.000
8351 00000000000638 2009044 -00001.000
8351 00000000000640 2009044 -00003.000
8351 00000000000642 2009044 -00001.000
8351 00000000000650 2009044 -00001.000
File B:
8351 00000000000636 006
8351 00000000000637 002
8351 00000000000642 001
Output:
006 8351 00000000000636 2009044 -00001.000
002 8351 00000000000637 2009044 -00002.000
000 8351 00000000000638 2009044 -00001.000
000 8351 00000000000640 2009044 -00003.000
001 8351 00000000000642 2009044 -00001.000
000 8351 00000000000650 2009044 -00001.000
Basically, if the second column of File A matches with the second column of File B. I need to write the third column of file B and the complete line from File A.
If not matched I need to write 000 and then the complete line in File A.
I tried some awk commands.. but didnt work. This below code i wrote to get the matched record and write the third column and the file A. But the third column is not getting written.
Any help will be much appreciated.
awk '
NR==FNR{a[$2]=$2;next}
a[$2]{print a[$3] $0}' $ZEROSTOCK $INFILE > $INTEMP