Frequency of a Character in a String [Shell Program]



clear


echo "Enter the
String:\c"


read str


echo "Enter the
character:\c"


read ch


n=0


i=`expr
"$str" : ".*"`





while [ $i -ne 0 ]


do


 m=`echo $str|cut -c $i`


 if [ "$m" = "$ch" ];then


 
n
=`expr $n + 1`


 fi


 i=`expr $i - 1`


done





echo "The
frequency is :"
$n


 





0 Comments