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 givin text

Posted By: Bogohardt Fischer     Category: Unix / Linux / Ubuntu     Views: 9411

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

Code for Write a shell program to count number of words, characters,white spaces and special symbols in a givin 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: 



Bogohardt Fischer
Bogohardt Fischer author of Write a shell program to count number of words, characters,white spaces and special symbols in a givin text is from Frankfurt, Germany.
 
View All Articles

Related Articles and Code:


 

Other Interesting Articles in Unix / Linux / Ubuntu:


 
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!