bash search for string in each line of file
While I would suggest to simply use grep too, the question is open, why you approach didn't work. Here a self referential modification of your second approach - with keyword 'bash' to match itself:
#!/bin/bashcnty=bash while read -r linedo case $line in *${cnty}*) echo $line " yes" >> bashgrep.log ;; *) echo "no" ;; esacdone < bashgrep.sh
The keypoint is while read -r line ... < FILE
. Your command with cat involves String splitting, so every single word is processed in the loop, not every line.
The same problem in example 1.