Hi,
I have 2 tab-delimited input files as follows.
file1.tab:
green A apple
red B apple
file2.tab:
apple - A;Z
Objective:
Return $1 of file1 if,
. $1 of file2 matches $3 of file1 and,
. any single element (separated by ";") in $3 of file2 is present in $2 of file1
In order to get:
green
The following code returns a blank output, since it seems to retain only the last iteration of file1.
gawk '
BEGIN{FS=OFS="\t"}
NR==FNR{
letter[$3]=$2
color[$3]=$1
next
}
{
a = split($3, b, ";")
for(i=1; i<=a; i++){
if($1 in letter && letter[$1] ~ b){
print color[$1]
}
}
}' file1.tab file2.tab