shell- find occurence of a character or a word within another string - bash


echo "enter a string"
read s

echo "enter a word to search in string"
read search_word

s2=` echo $s | grep -o $search_word | wc -l `

echo "The number of occurences is $s2"
Post a Comment