Q. I have a file which is of lower and upper case and want to convert it to upper case. How can I do that using a shell script?
This can be achieved by using tr or sed command. Below are two examples on do that.
#!/bin/bash
read -p "Please enter the file name whose content to be converted to upper case: " FILE1
tr '[a-z]' '[A-Z]' < $FILE1 >file2
mv file2 $FILE1
echo "Done the changes to file $FILE1"
Through sed command
#!/bin/bash
read -p "Please enter the file name whose content to be converted to upper case: " FILE1
sed -ir 's/(.*)/U1/g' $FILE1
echo "Done the changes to the file."
Do let us know if you know other way to do this.
For converting upper case to lower case use below scripts
with tr command
#!/bin/bash
read -p "Please enter the file name whose content to be converted to upper case: " FILE1
tr '[A-Z]' '[a-z]' < $FILE1 >file2
mv file2 $FILE1
echo "Done the changes to file $FILE1"
With SED command.
#!/bin/bash
read -p "Please enter the file name whose content to be converted to upper case: " FILE1
sed -ir 's/(.*)/L1/g' $FILE1
echo "Done the changes to the file."
Save the files execute them to get your files converted to upper/lower case.
Ffor string convertion click on “Shell scripting: How to convert a string in to uppercase”
Latest posts by Surendra Anne (see all)
- Docker: How to copy files to/from docker container - June 30, 2020
- Anisble: ERROR! unexpected parameter type in action:
Fix - June 29, 2020 - FREE: JOIN OUR DEVOPS TELEGRAM GROUPS - August 2, 2019
- Review: Whizlabs Practice Tests for AWS Certified Solutions Architect Professional (CSAP) - August 27, 2018
- How to use ohai/chef-shell to get node attributes - July 19, 2018