Monday, January 20, 2014

Unix and Shell Programming - Count and Replace the Character

with 0 Comment
clear
echo "Count and Replace the character"
echo "---------------------------------------"
echo "Enter The String"
read string
d='echo $string|wc -c'
d='expr $d -l'
echo "Total No.of Character in a String:"$d
echo "Enter the string to be searched"
read str
echo "Enter Which character should be replaced"
read r
count=0
i=1
newstr=""
while[$i -le $d]
do
s='expr $string|cut -c $i'
if[$s=$str]
then
newstr='echo $newstr$r'
count='expr $count+1'
else
newstr='echo $newstr$s'
fi
i='expr $i+1'
done
if[$count=0]
then
echo "$str is not present in the String" $string
else
echo "$str is present in the String" $string
echo "The Original String is" $string
echo "The New String is" $newstr
fi

-------------
OUTPUT:
-------------
Count and Replace the Charcter
--------------------------------------
Enter the String
Welcoke

Total No of Character in a String:7

Enter The String to be Searched
k

Enter Which Character should be Replaced
m
k is present in the string welcoke

The Original String is Welcoke

The New String is welcome

0 comments:

Post a Comment

Powered by Blogger.

Blog Archive