array[1] is a string pulled from a 30k lines CSV: example:
samsung black 2014
I need match those lines with one of the values contained within an array (arrayItems).
arrayItems contains 221 values like:
apple
sony
samsung
The actual script:
while IFS=$';' read -r -a array
do
mapfile -t arrayItems < $itemsFile
## now loop through the above array
for itemToFind in "${arrayItems[@]}"
do
itemFound=""
itemFound="$(echo ${array[1]} | grep -o '^$itemToFind')"
if [ -n "$itemFound" ]
then
echo $itemFound
# so end to search in case the item is found
break
fi
done
# here I do something with ${array[2]}, ${array[4]} line by line and so on,
# so I can't match the whole file $file_in at once but online line by line.
done < $file_in
The problem is that grep don't match.
but works If I try to hardcode $itemToFind like this:
itemFound="$(echo ${array[1]} | grep -o '^samsung')"
Another thing is... how to do it faster as $file_in is a 30k lines CSV?