bash count occurrences of string in array code example
Example 1: bash count occurrences of string in array
let count=0
for x in ${my_array[*]}; do
if [ $x == 'abc' ]
then
count=$((count+1))
fi
done
Example 2: bash count occurrences of string in array
for word in ${myarr[*]}; do
echo $word
done | grep -c "hello"