If it's a small file, you can use read
to split the line.
while IFS=, read fruit count; do
echo "I have $fruit and the count is $count"
done < file.txt
For larger files, it is inefficient to iterate using bash
, and something like awk
to read the entire file would be more appropriate.