Virajsinh

Shell_Script_OS_2

Oct 30th, 2017
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. i=1
  2.  
  3. while [ $i=1 ]
  4. do
  5.  
  6. echo "--------------------"
  7. echo "1. Compare String"
  8. echo "2. Combine String"
  9. echo "3. Find Length Of The String"
  10. echo "4. Reverse The String"
  11. echo "5. Occurance a Particular Word"
  12. echo "6. Exit"
  13. echo "--------------------"
  14.  
  15. echo -n "Enter Your Option :"
  16. read ch
  17.  
  18. case $ch in
  19.  
  20. 1) echo "Compare String"
  21. echo -n "Enter First String : "
  22. read str1
  23. echo -n "Enter Second String : "
  24. read str2
  25.  
  26. if [ $str1 = $str2 ]
  27. then
  28. echo "--------------------"
  29. echo "String is Same"
  30. echo "--------------------"
  31. else
  32. echo "--------------------"
  33. echo "String is Not Same"
  34. echo "--------------------"
  35. fi
  36.  
  37. ;;
  38.  
  39. 2) echo "Combine String"
  40.  
  41. echo -n "Enter First String : "
  42. read strc1
  43. echo -n "Enter Second String : "
  44. read strc2
  45.  
  46. echo "$strc1 $strc2"
  47. ;;
  48.  
  49. 3)echo "Find Length Of The String"
  50. echo -n "Enter String :"
  51. read string
  52.  
  53. len=`echo $string | wc -c`
  54. len=`expr $len - 1`
  55. echo $len
  56.  
  57. ;;
  58.  
  59. 4)echo "Reverse The String"
  60. echo -n "Enter String :"
  61. read str
  62. revs=`echo -n $str | rev`
  63. echo $revs
  64. ;;
  65.  
  66. 5)echo "Occurance a Particular Word"
  67. echo -n "Enter String : "
  68. read ostr
  69. echo -n "Enter Word : "
  70. read word
  71.  
  72. file1=`echo $ostr | cat > str.lst`
  73. wrd=`grep -o $word str.lst | cat > occ.lst`
  74. count=`grep -c $word occ.lst`
  75. echo $count
  76. ;;
  77.  
  78. 6)echo "Exit"
  79. exit
  80. ;;
  81.  
  82. *) echo "Enter Proper Choice"
  83. ;;
  84.  
  85. esac
  86.  
  87. echo -n "Enter 2 to Exit :"
  88. read i
  89. if [ $i -ne 1 ]
  90. then
  91. exit
  92. fi
  93. done
Add Comment
Please, Sign In to add comment