#
#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.         
#
clear
echo "==================== AVAILABLE CHOICES ========================="
echo "1. Compare two strings"
echo "2. Join two strings"
echo "3. Find length of a given string"
echo "4. Occurance of character and word in a string"
echo "5. Reverse the string"
echo "E. Exit"
echo "================================================================"
echo "Enter your choice :"
read choice
while [ "$choice" != "e" -o "$choice" != "E" ]
do
	case $choice in
	"1")
		echo -n "Enter first string :"	
		read firststr
		echo -n "Enter second string :"	
		read secondstr
		#if [ "$firststr" = "$secondstr" ] #FOR CASE SENSITIVE CHECK
		if [ `echo $firststr | grep -ci $secondstr` -gt 0 ] #FOR CASE INSENSITIVE CHECK
		then
			echo "Both strings are same"
		else
			echo "Both strings are different"
		fi
	;;	
	"2")
		echo -n "Enter first string :"	
		read firststr
		echo -n "Enter second string :"	
		read secondstr
		echo "Joining of two string is : $firststr$secondstr"
	;;
	"3")
		echo -n "Enter any string :"	
		read string
		length=$(echo $string | wc -c)
		length=$(expr $length - 1)
		echo "Length of string is "$length
	;;
	"4")
		echo "Enter any string :"	
		string=$(cat) #ctrl + d to terminate
		characters=$(echo $string | wc -c)
		lines=$(echo "$string" | wc -l)
		echo "No of characters : $characters"
		echo "No of lines : $lines"
	
	;;
	"5")
		echo "Enter any string :"	
		read string
		#echo $(echo $string | rev ) 1-solution
		length=$(echo $string | wc -c)
		length=$(expr $length - 1)
		i=$length
		s=""
		while [ $i -gt 0 ]
		do
			 s=$s$(echo $string | cut -c$i)
			i=$(expr $i - 1)
		done
		echo "Reverse of the string is $s"
	;;
	[eE])
		exit;
	;;
	*)
		echo "Invalid choice"
	;;
	esac
	read temp
	clear
	echo "==================== AVAILABLE CHOICES ========================="
	echo "1. Compare two strings"
	echo "2. Join two strings"o
	echo "3. Find length of a given string"
	echo "4. Occurance of character and word in a string"
	echo "5. Reverse the string"
	echo "E. Exit"
	echo "================================================================"
	echo "Enter your choice :"
	read choice
done