• Source
    1. #
    2. #Write a script which reads a text file and output the following
    3. #Count of character, words and lines.
    4. #File in reverse.
    5. #Frequency of particular word in the file.
    6. #Lower case letter in place of upper case letter.
    7. #
    8. clear
    9. echo "Enter name of the text file :"
    10. read filename
    11.  
    12. if [ ! -f $filename ]
    13. then
    14. echo "Please enter proper file name"
    15. exit
    16. fi
    17.  
    18. echo "====================== AVAILABLE CHOICES ======================"
    19. echo "1. Count of character, words and lines"
    20. echo "2. File in reverse"
    21. echo "3. Frequency of particular word in the file"
    22. echo "4. Lower case letter in place of upper case letter"
    23. echo "E. Exit"
    24. echo "==============================================================="
    25. echo -n "Enter your choice :"
    26. read choice
    27. case $choice in
    28. 1)
    29. echo "Total characters :"$(cat $filename | wc -c)
    30. echo "Total words :"$(cat $filename | wc -w)
    31. echo "Total lines :"$(cat $filename | wc -l)
    32. ;;
    33. 2)
    34. echo "========= FILE IN REVERSE ORDER ========="
    35. str=$(cat $filename | rev)
    36. echo "$str"
    37. ;;
    38. 3)
    39. echo -n "Enter word to find frequencey :"
    40. read word
    41. c=$(cat $filename | grep -wci $word)
    42. echo "Frequency of word \"$word\" in the file is "$c
    43. ;;
    44. 4)
    45. str=$(cat $filename)
    46. content=$(echo "$str" | tr [A-Z] [a-z])
    47. echo "$content" > $filename
    48. echo "Uppercase letters are convered to lowercase in file"
    49. ;;
    50. [eE])
    51. exit;
    52. ;;
    53. esac