Logo 
Search:

Unix / Linux / Ubuntu Articles

Submit Article
Home » Articles » Unix / Linux / Ubuntu » Homework HelpRSS Feeds

Write a shell program to count number of words, characters, white spaces and special symbols in a given text

Posted By: Lauren Hughes     Category: Unix / Linux / Ubuntu     Views: 11582

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

Code for Write a shell program to count number of words, characters, white spaces and special symbols in a given text in Unix / Linux / Ubuntu

echo Enter a text
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
  
Share: 



Lauren Hughes
Lauren Hughes author of Write a shell program to count number of words, characters, white spaces and special symbols in a given text is from London, United Kingdom.
 
View All Articles

Related Articles and Code:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!