I need to verify that all images mentioned in a csv are present inside a folder. I wrote a small shell script for that
#!/bin/zsh
red='\033[0;31m'
color_Off='\033[0m'
csvfile=$1
imgpath=$2
cat $csvfile | while IFS=, read -r filename rurl
do
if [ -f "${imgpath}/${filename}" ]
then
echo -n
else
echo -e "$filename ${red}MISSING${color_Off}"
fi
done
My CSV looks something like
Image1.jpg,detail-1
Image2.jpg,detail-1
Image3.jpg,detail-1
The csv was created by excel.
Now all 3 images are present in imgpath
but for some reason my output says
Image1.jpg MISSING
Upon using zsh -x
to run the script i found that my CSV file has a BOM at the very beginning making the image name as \ufeffImage1.jpg
which is causing the whole issue.
How can I ignore a BOM(byte-order marker) in a while read operation?