I googled a lot my problem and tested different solutions, but none seem to work. I even used the same command in advance with success but now I do not manage to get my desired output.
I have file1
AAA;123456789A
BBB;123456789B
CCC;123456789C
And file2
1;2;3;CCC;pippo
1;2;3;AAA;pippo
1;2;3;BBB;pippo
1;2;3;*;pippo
My desired output is this:
1;2;3;CCC;pippo;CCC;123456789C
1;2;3;AAA;pippo;AAA;123456789A
1;2;3;BBB;pippo;BBB;123456789B
I tried with this command:
awk -F";" -v OFS=";" 'FNR == NR {a[$10]=$1; b[$20]=$2; next}($10 in a){ if(match(a[$10],$4)) print $0,a[$10],b[$20]}' file1 file2
But I get this output (only one entry, even with bigger files):
1;2;3;CCC;pippo;CCC;123456789C
What am I doing wrong? If it manages for one it should for all the other. Why is this not happening?
Also why if I set a[$1]=$1
it doesn't work?
Thank you for helping!
If possible could you explain the answer? So next time I won't have to ask for help!
EDIT: Sorry, I did not mention (since I wanted to keep the example minimal) that in file2 some fields are just "*". And I'd like to add an "else doesn't match do something".