Write a shell script to Perform Following String Operations
Definition : Write A Script To Perform Following String Operations Using Menu:
1. COMPARE
TWO STRINGS.
2. JOIN
TWO STRINGS.
3. FIND
THE LENGTH OF A GIVEN STRING.
4. OCCURRENCE
OF CHARACTER AND WORDS
5. REVERSE THE STRING.
File Name : ex18.sh
clear
choice=y
while
[ "$choice" = "y" ]
do
echo
"____________________________________________"
echo
"1. COMPARE TWO STRINGS"
echo
"2. JOIN TWO STRINGS"
echo
"3. FIND THE LENGTH OF A GIVEN STRING"
echo
"4. OCCURRENCE OF CHARACTER AND WORDS"
echo
"5. REVERSE THE STRING"
echo
"6. EXIT"
echo
"____________________________________________"
echo
"Enter Choice: \c"
read
ch
echo
"____________________________________________"
case
$ch in
1)
echo "Enter String1: \c"
read str1
echo "Enter String2: \c"
read str2
if [ $str1 = $str2 ]
then
echo "String is
equal"
else
echo "String is not
equal"
fi
;;
2)
echo "Enter String1: \c"
read str1
echo "Enter String2: \c"
read str2
str3=$str1$str2
echo "Join String: \c" $str3
;;
3)
len=0
echo "Enter String1: \c"
read str1
len=$(echo "$str1" | wc
-c)
len=`expr $len - 1`
echo "Length: " $len
;;
4)
echo "Enter String: \c"
read str
echo "Enter Word to find : \c"
read word
echo $str | cat > str1.txt
grep -o $word str1.txt | cat >
str2.txt
count=`grep -c $word str2.txt`
echo "Count: \c"$count
;;
5)
echo "Enter String1: \c"
read str
len=`expr $str | wc -c`
len=`expr $len - 1`
while [ $len -gt 0 ]
do
rev=`expr $str | cut -c $len`
ans=$ans$rev
len=`expr $len - 1`
done
echo "Reverse String: \c"$ans
;;
6) exit ;;
*) echo "Invalid Choice ....." ;;
esac
echo "Do u want to continue.....?
[y/n]"
read choice
case $choice in
Y|y) choice=y;;
N|n) choice=n;;
*) choice=y;;
esac
done
Subscribe to:
Post Comments (Atom)
Subjects
- WordPress
- Mobile Computing-4649303 Practical Solution
- Android Programming New Syllabus Theory
- PHP LAMP Question Bank
- PHP LAMP Theory
- Step by Step Android Example
- Android Practical
- Android Theory
- Android Question Bank
- Networking FON Practical
- Networking FON Theory
- OS Practical
- OS Theory
- HTML
- JavaScript
- J2EE WTAD Theory
- J2EE WTAD Question Bank
- J2EE WTAD Quick Guide
- J2EE WTAD GTU Papers
- J2EE WTAD Practical
- Python
- JAVA Theory
- JAVA Practical
- MIS
Categories
- Android (55)
- c (11)
- Configure Tomcat7 (2)
- CSS (3)
- Decryption (16)
- Difference (1)
- Encryption (16)
- Error Detection and Correction Techniques (3)
- FON (27)
- Framing Technic (2)
- install Tomcat (2)
- J2EE (29)
- JAVA (13)
- JavaScript (19)
- linux (8)
- OS (17)
- PHP (11)
- Protocol (3)
- SERVER SOCKET PROGRAMING (7)
- Servlet (13)
- shell script (33)
- unix (22)
- WTAD (34)
Blog Archive
-
▼
2012
(79)
-
▼
November
(15)
- unix grep command
- Write a script to learn command line argument
- Write a script to display the last modified file
- Write a script to display all lines of a file in a...
- Write a script to display all words of a file in a...
- Write a script to check whether a given number is ...
- Write a script to check whether a given string is ...
- Write a shell script to mathematics calculation
- Write a shell script to Perform Following String O...
- Write a Shell Script for Simple Database Managemen...
- Write a shell script to check whether the named us...
- Write a script which reads a text file and output ...
- Write a script to make following file and director...
- Write a shell script to add the statement #include...
- Write a script to implement the following commands...
-
▼
November
(15)
Total Pageviews
© BipinRupadiya.com. Powered by Blogger.
0 comments:
Post a Comment