Q: Write a shell script for manipulating the case of input text.
Enter your choice
1.print file in lower case 2.print file in upper case 3.string to lower case
4.string to upper case 5.Invert case of input string 6.exit
1
Files in the current folder are as follows
grpb7.sh grpb7.sh~ sample
Enter the file name to be printed in lower case:
sample
Actual contents of file
ThiS i$ a SaMPle FiLe f0r te$tinG tHE ProGr@m
this i$ a sample file f0r te$ting the progr@m
Operation Successful
Enter your choice
1.print file in lower case 2.print file in upper case 3.string to lower case
4.string to upper case 5.Invert case of input string 6.exit
2
Files in the current folder are as follows
grpb7.sh grpb7.sh~ sample
Enter the file name to be printed in upper case:
sample
Contents before conversion
ThiS i$ a SaMPle FiLe f0r te$tinG tHE ProGr@m
THIS I$ A SAMPLE FILE F0R TE$TING THE PROGR@M
Operation successful
Enter your choice
1.print file in lower case 2.print file in upper case 3.string to lower case
4.string to upper case 5.Invert case of input string 6.exit
3
Enter the string to be converted:
SaMpLE
String in lower case is: sample
Enter your choice
1.print file in lower case 2.print file in upper case 3.string to lower case
4.string to upper case 5.Invert case of input string 6.exit
4
Enter the string to be converted:
Te$t
String in uppercase is: TE$T
Enter your choice
1.print file in lower case 2.print file in upper case 3.string to lower case
4.string to upper case 5.Invert case of input string 6.exit
5
Enter the string to be inverted
InvERT !t
Inverted string is : iNVert !T
Enter your choice
1.print file in lower case 2.print file in upper case 3.string to lower case
4.string to upper case 5.Invert case of input string 6.exit
6
Source Code
#!/bin/bash while true do echo "Enter your choice" echo -e "1.print file in lower case \t2.print file in upper case \t3.string to lower case \t\n4.string to upper case \t\t5.Invert case of input string \t6.exit" read choice case $choice in 1) echo "Files in the current folder are as follows" ls echo "Enter the file name to be printed in lower case:" read f1 echo "Actual contents of file " cat $f1 tr '[A-Z]' '[a-z]' <$f1 echo "Operation Successful" ;; 2) echo "Files in the current folder are as follows" ls echo "Enter the file name to be printed in upper case:" read f2 echo "Contents before conversion" cat $f2 tr '[a-z]' '[A-Z]' <$f2 echo "Operation successful" ;; 3) echo "Enter the string to be converted:" read str ans=${str,,} echo "String in lower case is: "$ans ;; 4) echo "Enter the string to be converted:" read str ans=${str^^} echo "String in uppercase is: " $ans ;; 5) echo "Enter the string to be inverted" read str ans=${str~~} echo "Inverted string is :" $ans ;; 6)exit ;; esac done
Output
[student@localhost loweruppercase]$ sh grpb7.shEnter your choice
1.print file in lower case 2.print file in upper case 3.string to lower case
4.string to upper case 5.Invert case of input string 6.exit
1
Files in the current folder are as follows
grpb7.sh grpb7.sh~ sample
Enter the file name to be printed in lower case:
sample
Actual contents of file
ThiS i$ a SaMPle FiLe f0r te$tinG tHE ProGr@m
this i$ a sample file f0r te$ting the progr@m
Operation Successful
Enter your choice
1.print file in lower case 2.print file in upper case 3.string to lower case
4.string to upper case 5.Invert case of input string 6.exit
2
Files in the current folder are as follows
grpb7.sh grpb7.sh~ sample
Enter the file name to be printed in upper case:
sample
Contents before conversion
ThiS i$ a SaMPle FiLe f0r te$tinG tHE ProGr@m
THIS I$ A SAMPLE FILE F0R TE$TING THE PROGR@M
Operation successful
Enter your choice
1.print file in lower case 2.print file in upper case 3.string to lower case
4.string to upper case 5.Invert case of input string 6.exit
3
Enter the string to be converted:
SaMpLE
String in lower case is: sample
Enter your choice
1.print file in lower case 2.print file in upper case 3.string to lower case
4.string to upper case 5.Invert case of input string 6.exit
4
Enter the string to be converted:
Te$t
String in uppercase is: TE$T
Enter your choice
1.print file in lower case 2.print file in upper case 3.string to lower case
4.string to upper case 5.Invert case of input string 6.exit
5
Enter the string to be inverted
InvERT !t
Inverted string is : iNVert !T
Enter your choice
1.print file in lower case 2.print file in upper case 3.string to lower case
4.string to upper case 5.Invert case of input string 6.exit
6
No comments:
Post a Comment