• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

How to convert text files to all upper or lower case

by admin

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:]' < input.txt > 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' < input.txt > output.txt

There is also special syntax in tr for specifying this sort of range for upper-and lower-case conversions:

$ tr '[:lower:]' '[:upper:]' < input.txt > 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

Filed Under: DevOps, Linux, Shell Scripting

Some more articles you might also be interested in …

  1. genfstab Command Examples in Linux
  2. How to Enable Thin LVM Automatic Extension
  3. autorandr Command Examples in Linux
  4. rbash – Set Restricted shell in Linux
  5. How to change hostname in CentOS/RHEL 7
  6. bsdtar command – Read and write tape archive files
  7. engrampa: command not found
  8. colrm Command Examples in Linux
  9. timedatectl: command not found
  10. How to configure apache virtual host on ubuntu

You May Also Like

Primary Sidebar

Recent Posts

  • nixos-rebuild Command Examples in Linux
  • nixos-option: Command Examples in Linux
  • nixos-container : Command Examples in Linux
  • nitrogen Command Examples in Linux

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright