The answer is rather simple: You use a[$3] to refer to the third column of file1. However
- you use the array
ato store the second column offile1, and never the third column, and - you only ever use the first column (the numbers) as "keys", so attempting to access, say,
a["info 1"](as youra[$3]would do on the first line of processingfile2) will return nothing.
The following program would do:
awk 'BEGIN{FS=OFS="|"} NR==FNR{d[$1]=$2;t[$1]=$3;next} ($1 in d) {print $2,d[$1],t[$1],$3}' file1.txt file2.txt > file3.txt
This sets | as field separator for input and output.
- When processing
file1.txt, it stores the day in an arraydand the time in an arrayt, with the first column (number) as key. - When processing
file2.txt, it prints column 2, the date and time corresponding to column 1, and then the "info" value in column 3, using|as output separator.