Thursday, 4 April 2019

Shell script to count the vowels in the given string

#script to count the number of vowels in the given string using if
echo Enter string
read str
count=0
len=`echo $str | wc -c`
len=`expr $len - 1`
while test $len -gt 0
do
     temp=`echo $str | cut -c $len | tr [A-Z]  [a-z]`
     len=`expr $len - 1`
     if test  "$temp" = "a" -o "$temp" = "e" -o "$temp" = "i" -o
            "$temp" ="o"  -o  "$temp" = "u"
     then
                           echo “$temp”
                           count=`expr $count + 1`
     fi
done
echo Number of vowels in the given string \"$str\" are "$count"
 


OUTPUT
Safi> sh vwlcnt.sh
Enter string
good
“o”
“o”
Number of vowels in the given string "good" are 2

 

No comments:

Post a Comment