Logo 
Search:

Dos Articles

Submit Article
Home » Articles » Dos » ScriptsRSS Feeds

Read a file and count number of word, character, lines, display in reverse, convert lower to upper, upper to lower case,count particular word in file

Posted By: Leon Evans     Category: Dos     Views: 10131

Script to reads text file and perform below operations.
1) Count character,words and lines
2) Display content in reverse
3) Count particular word
4) Convert upper to lower
5) Convert lower to upper

Code for Read a file and count number of word, character, lines, display in reverse, convert lower to upper, upper to lower case,count particular word in file in Dos

echo "Enter File Name"
read fname
echo "
   1) Count character,words and lines
   2) Display content in reverse
   3) Count particular word
   4) Convert upper to lower
   5) Convert lower to upper

echo "Enter Choice: "
read ch
case $ch in
1)
        echo Total Character:
        wc -c $fname
        echo Total Words:
        wc -w $fname
        echo Total Lines:
        wc -l $fname
        ;;
2)
        rev $fname
        ;;
3)
        echo Enter word to find
       read w
        echo Frequency:
        grep  -c "$w" $fname
        ;;
4)
        echo Enter Text
        read text
        echo $text | tr "[A-Z]" "[a-z]"
        ;;
5)
        echo Enter Text
        read text
        echo $text | tr "[a-z]" "[A-Z]"
        ;;
*)
        echo Wrong Choice
        ;;
esac


output:

$ sh fileOp.sh
Enter File Name
testData.txt

     1) Count character,words and lines
     2) Display content in reverse
     3) Count particular word
     4) Convert upper to lower
     5) Convert lower to upper
  
Enter Choice:
1
Total Character:
     36 testData.txt
Total Words:
      5 testData.txt
Total Lines:
      2 testData.txt

Enter Choice:
2
etis
.etis moc.elpmaxe-xatnys si tI

Enter Choice:
3
Enter word to find site
Frequency:
2

Enter Choice:
4
Enter Text
NONE
none

Enter Choice:
5
Enter Text
null
NULL
  
Share: 



Leon Evans
Leon Evans author of Read a file and count number of word, character, lines, display in reverse, convert lower to upper, upper to lower case,count particular word in file is from London, United Kingdom.
 
View All Articles

Related Articles and Code:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!