Shell Script to Convert a File Content to Lower Case or Upper Case Last Updated : 23 Jul, 2025 Comments Improve Suggest changes Like Article Like Report Here we are going to see how to convert a file to lower case or upper case as specified by the user. We are going to write a POSIX compatible shell script which is going to give us the desired output after input of files such as sample.txt, a text file with a combination of lowercase, uppercase, digits and special character Example: File Content this is lowercase THIS IS UPPERCASE $P3C14L C#4R4CT3R$ 1234567890 OUTPUT Uppercase THIS IS LOWERCASE THIS IS UPPERCASE $P3C14L C#4R4CT3R$ 1234567890 Lowercase this is lowercase this is uppercase $p3c14l c#4r4ct3r$ 1234567890Approach:Ask User Choice if they want to convert from Uppercase to Lowercase or vice-versaRead the choiceGet into the Switch case depending on the choice. while exiting if the choice is none of the above-mentioned.Asking user for the filenameChecking if file exists, if not then exit with error code 1, otherwise continueTranslating the file content as per the previous selected user choice and printing the output by the use of tr command.End of ScriptShell Script #!/bin/sh # shebang to specify that this is an shell script # Function to get File getFile(){ # Reading txtFileName to convert it's content echo -n "Enter File Name:" read txtFileName # Checking if file exist if [ ! -f $txtFileName ]; then echo "File Name $txtFileName does not exists." exit 1 fi } clear echo "1. Uppercase to Lowercase " echo "2. Lowercase to Uppercase" echo "3. Exit" echo -n "Enter your Choice(1-3):" read Ch case "$Ch" in 1) # Function Call to get File getFile # Converting to lower case if user choose 1 echo "Converting Upper-case to Lower-Case " tr '[A-Z]' '[a-z]' <$txtFileName ;; 2) # Function Call to get File getFile # Converting to upper case if user cho0se 2 echo "Converting Lower-Case to Upper-Case " tr '[a-z]' '[A-Z]' <$txtFileName ;; *) # exiting for all other cases echo "Exiting..." exit ;; esac Output: Sample text file and making our script executable Showcasing content of sample text file with cat command and modifying our script by making it executable with chmod command. Conversion Input and OutputConverting file content from uppercase to lowercaseConverting file content from lowercase to uppercaseRunning on non-existing filesIn the Case File does not exist Comment More infoAdvertise with us Next Article How to Convert a String to Lower or Upper Case in Ruby? V vabs Follow Improve Article Tags : Linux-Unix Shell Script Similar Reads How to Convert a String to Lower or Upper Case in Ruby? In this article, we will discuss how to convert a string to lower or upper case in Ruby. We can convert a string to lower or upper case using built-in methods provided in the Ruby language. Table of Content Using DowncaseUsing UpcaseUsing CapitalizeUsing DowncaseThe downcase method is used to conver 2 min read How to convert the first character to uppercase using PHP ? A string is a combination of words combined together. The first character of the string can be converted to an upper case in case it is a lower case alphabetic character. Approach 1 : Using chr() method Step 1: The first character of a string can be extracted using the first index, str[0] returns th 3 min read Bash Script to Check whether character entered is Upper, Lower, Digit, Consonant, or Vowel In Bash scripting, it's often necessary to analyze user input and determine the type of character entered. This information can be used for various purposes, like data validation, formatting, and logic control. This article demonstrates how to write a Bash script that checks whether a character ente 4 min read How To Change Uppercase And Lowercase Text In Google Docs Google Docs is a free online document editor provided by Google. Google Docs makes it easier to create a document for personal and professional uses with a variety of features. Some of the features in Google Docs are customizing font styles, font size, text alignment, and inserting media such as ima 4 min read How to convert first character of all the words uppercase using PHP ? To convert the first character of all the words present in a string to uppercase, we just need to use one PHP function i.e. ucwords().ucwords(string,delimiters)This function takes 2 parameters. The first one is the string which is mandatory. The second parameter is the delimiter. Example 1:PHP<?p 2 min read How to create half of the string in uppercase and the other half in lowercase? The first thing that we have to keep in my mind while solving this kind of problem is that the strings are immutable i.e, If I am taking the following string var string1 = "geeksforgeeks";string1[0] = "G";console.log(string1);As strings are immutable, so we cannot change the character of the string, 9 min read Like