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

| 0 Comments

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

Leave a Reply