com awk :
awk 'FNR==NR{a[$1]=$2"\t"$3} FNR!=NR{split($2,b,"-"); $0=$0"\t"a[b[1]];print}' file1 file2
-
FNR==NRaplica-se ao primeiro arquivofile1:-
a[$1]=$2"\t"$3preenche a matrizacom o 2º e 3º campo e como índice usa o 1º campo.
-
-
FNR!=NRaplica-se ao segundo arquivofile2:-
split($2,b,"-")divide o segundo campo em-. -
$0=$0"\t"a[b[1]]acrescenta os dois valores à linha. -
printimprime a linha.
-
A saída:
text1 ABC1-AB text2 text3 1 3
text2 ABC2-AB text1 4 3
text3 ABC1-CD text2 1 3
text4 ABC5-AB text3 text4