I have two files
file1.txt
a|1|cd
a|2|cd
a|4|cd
file2.txt
a|0001|hj|df
a|0002|ed|nb
a|0003|vf|za
a|0004|er|ns
a|0005|oi|lk
I need a create new file with the lines matched by de second column of the files, I try by then next code
awk -F"|" 'NR==FNR{a[$2]++;next} a[$2] ' file1.txt file2.txt
but no found records, because file1.txt in second column doesn't contain 0 at the left I have the instruction
awk -F"|" 'NR==FNR{a[$(printf("%09d\n", $2))]++;next} a[$2]'
but doesn't work.
The result must be:
file3.txt
a|0001|hj|df
a|0002|ed|nb
a|0004|er|ns