• 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. 7za – File archiver with a high compression ratio (Command Examples)
  2. Unable to Run X Applications Through SSH in Linux
  3. ncat: command not found
  4. “az storage table” Command Examples
  5. strace: command not found
  6. How to Check if any of the RPM files were tampered with
  7. How to install git on ubuntu 16.04
  8. hlint: command not found
  9. sbatch: command not found
  10. The locate Command in Linux

You May Also Like

Primary Sidebar

Recent Posts

  • batch: Execute commands at a later time when the system load levels permit
  • bat: Print and concatenate files
  • bastet: Clone of the game Tetris in the terminal
  • bashmarks: Save and jump to commonly used directories using 1 character commands

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright