Home Linux Write a shell script to count the number of words, characters, spaces and special symbols in a given text.

Write a shell script to count the number of words, characters, spaces and special symbols in a given text.

1 min read
0
0
77

 Write a shell script to count the number of words, characters, spaces and special symbols in a given text.


echo "Enter the text: \n"

read text

w=`echo $text | wc -w`

w=`expr $w`

c=`echo $text | wc -c`

c=`expr $c - 1`

s=0

alpha=0

j=` `

n=1

while [ $n -le $c ]

do

ch=`echo $text | cut -c $n`

if test $ch=$j

then

s=`expr $s + 1`

fi

case $ch in

(a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z)

alpha=`expr $alpha + 1`;;

esac

n=`expr $n + 1`

done

special=`expr $c - $s - $alpha`

echo words=$w

echo characters=$c

echo spaces=$s

echo special symbols=$special

Load More Related Articles
Load More By coder coder
Load More In Linux

Leave a Reply

Your email address will not be published. Required fields are marked *

Check Also

Prime Or Not Prime vb.net Program.

Prime Or Not Prime . …