I need to match multiple values in a single column in a file:
example:
Source file:
abd,123,one
def,232,two
ghi,987,six
Target file:
12345,abcde,123
09876,zxvyr,566
56789,lmnop,232
Variable:
var1=`grep 2 sourcefile | awk '{print$1}'
essentially, echo "$var1" would read:
123
232
For loop:
for variable in ${var1[]}
do
cat targetfile | awk '{if ($3 == "$variable") print $1;}' > outputfile
done
in theory, the result set should be...
12345
56789
...however, when I run this, I get no errors but no output. I don't know where i've gone wrong. Any help would be greatly appriciated.
Thanks!