I have file1.txt:
1|2022-09-29|03:15:00
2|2022-09-29|10:50:00
3|2022-09-29|07:15:00
and file2.txt:
1|red|info 1
2|blue
3|yellow|info 2
and I want to connect this files into one, file3.txt, to make it looks like this:
red|2022-09-29|03:15:00|info 1
blue|2022-09-29|10:50:00|
yellow|2022-09-29|07:15:00|info 2
so I've tried to type a script:
#!/bin/bash
awk -F'|' 'NR==FNR {a[$1]=$2;next}  ($1 in a) {a[$1]=$2"|"a[$1]"|"a[$3]"|"$3; print a[$1]}' file1.txt file2.txt > file3.txt
but my output look like this:
red|2022-09-29||info 1
blue|2022-09-29||
yellow|2022-09-29||info 2
as you can see the 3rd part of file1.txt is missing and I can't figure it out why. I would be grateful for pointing out to me what I am doing wrong.

