I would like to merge file1 4th column with file2 1st column with awk and I would like to print 2nd column from file $1. If more than one match (could be more than 100), print it separated by comma.
FILE1:
alo descrip 1 PAPA
alo descrip 2 LOPA
alo descrip 3 REP
alo descrip 4 SEPO
dlo sapro 31 REP
dlo sapro 35 PAPA
FILE2:
PAPA klob trop
PAPA kopo topo
HOJ sasa laso
REP deso rez
SEPO raz ghul
REP kok loko
OUTPUT:
PAPA klob trop descrip,sapro
PAPA kopo topo descrip,sapro
HOJ sasa laso NA
REP deso rez descrip,sapro
SEPO raz ghul descrip
REP kok loko descrip,sapro
I tried:
awk -v FILE_A="FILE1" -v OFS="\t" 'BEGIN { while ( ( getline < FILE_A ) > 0 ) { VAL = $0 ; sub( /^[^ ]+ /, "", VAL ) ; DICT[ $1 ] = VAL } } { print $0, DICT[ $4 ] }' FILE2
but it doesn't work.