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”

The following two tabs change content below.
Mr Surendra Anne is from Vijayawada, Andhra Pradesh, India. He is a Linux/Open source supporter who believes in Hard work, A down to earth person, Likes to share knowledge with others, Loves dogs, Likes photography. He works as Devops Engineer with Taggle systems, an IOT automatic water metering company, Sydney . You can contact him at surendra (@) linuxnix dot com.