I have an array ${myarr[@]} with strings. ${myarr[@]} basically consists of lines and each line constists of words.
${myarr[@]}
world hello moo
Try this:
for word in ${myarr[*]}; do echo $word done | grep -c "hello"
Alternative (without loop):
grep -o hello <<< ${myarr[*]} | wc -l
No need for an external program:
count=0 for word in ${myarr[*]}; do if [[ $word =~ hello ]]; then (( count++ )) fi done echo $count