As usual, in Linux, there are more than 1 way to accomplish a task. To convert a file (input.txt) to all lower case (output.txt), choose any ONE of the following:
To convert a file (input.txt) to all lower case (output.txt)
1. dd: You may have used dd for many other purposes but it can be used for text conversions also.
$ dd if=input.txt of=output.txt conv=lcase
2. tr: You can translate all uppercase (A–Z) to lowercase characters (a-z) using the tr command and specifying a range of characters, as in:
There is also special syntax in tr for specifying this sort of range for upper and lower case conversions:
$ tr '[:upper:]' '[:lower:]' output.txt
3. awk: awk has a special function tolower for uppercase to lowercase conversion.
$ awk '{ print tolower($0) }' input.txt > output.txt
4. perl:
$ perl -pe '$_= lc($_)' input.txt > output.txt
5. sed:
$ sed -e 's/\(.*\)/\L\1/' input.txt > output.txt
We use the backreference \1 to refer to the entire line and the \L to convert to lower case.
To convert a file (input.txt) to all upper case (output.txt)
1. dd: Use below command to convert lowercase to uppercase.
$ dd if=input.txt of=output.txt conv=ucase
2. tr: You can translate all lowercase characters (a-z) to upercase (A–Z) using the tr command and specifying a range of characters, as in:
$ tr 'A-Z' 'a-z' output.txt
There is also special syntax in tr for specifying this sort of range for upper-and lower-case conversions:
$ tr '[:lower:]' '[:upper:]' output.txt
3. awk: awk has special function toupper for lowercase to uppercase conversion.
$ awk '{ print toupper($0) }' input.txt > output.txt
4. perl:
$ perl -pe '$_= uc($_)' input.txt > output.txt
5. sed:
$ sed -e 's/\(.*\)/\U\1/' input.txt > output.txt