• Contact
  • Contact Us
  • Disclamer
  • Home 1
  • Home 2
  • Home 3
  • Privacy Policy
Saturday, June 21, 2025
How VPS - How to use/setup VPS
  • Login
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon
No Result
View All Result
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon
No Result
View All Result
How VPS - How to use/setup VPS
No Result
View All Result
Home Operating System Linux

10 tr Command Examples in Linux

How VPS by How VPS
November 2, 2018
in Linux, Operating System
0
0
SHARES
50
VIEWS
Share on FacebookShare on Twitter

Contents

  1. Linux tr Command Examples

tr (short for translate) is a useful command line utility that translates and/or deletes characters from stdin input, and writes to stdout. It is a useful program for manipulating text on the command line.

In this article, we will explain some useful tr command examples for Linux newbies.

The syntax for running tr command is as follows, where characters in SET1 are translated to characters in SET2.

$ tr flags [SET1] [SET2]

Linux tr Command Examples

1. A simple tr command use case is to change all lower case letters in text to upper case and vice versa, as shown below.

$ cat linux.txt

linux is my life
linux has changed my life
linux is best and everthing to me..:)
$ cat domains.txt | tr [:lower:] [:upper:]

LINUX IS MY LIFE
LINUX HAS CHANGED MY LIFE
LINUX IS BEST AND EVERTHING TO ME..:)

2. Alternatively, you can use the following command to change all lower case letters to upper case in a file as shown.

$ cat linux.txt | tr [a-z] [A-Z]

LINUX IS MY LIFE
LINUX HAS CHANGED MY LIFE
LINUX IS BEST AND EVERTHING TO ME..:)

3. To save the results written to stdout in a file for later processing, use the shell’s output redirection feature (>) as shown.

$ cat linux.txt | tr [a-z] [A-Z] >output.txt
$ cat output.txt 

LINUX IS MY LIFE
LINUX HAS CHANGED MY LIFE
LINUX IS BEST AND EVERTHING TO ME..:)

4. In regards to the redirection, you can send input to tr using the input redirection and redirect the output to a file using the same command, as shown.

$ tr [a-z] [A-Z] < linux.txt >output.txt

5. Another useful feature is, you can use the -d flag to delete characters, for example to remove the spaces in the domain names using the following command.

$ cat domains.txt

www. tecmint. com
www. fossmint. com
www. linuxsay. com
$ cat domains.txt | tr -d '' 

www.tecmint.com
www.fossmint.com
www.linuxsay.com

6. If there are repeated characters in a sequence (for instance double spaces) in the text you are processing, you can use the -s option to squeeze the characters leaving only one occurrence of it.

$ cat domains.txt

www.tecmint.....com
www.fossmint.com
www.linuxsay.com
$ cat domains.txt | tr -s '' 

www.tecmint.com
www.fossmint.com
www.linuxsay.com

7. The -c option tells tr to use the complement in the given of SET. In this example, we want to delete all the letters and only leave the UID.

$ echo "My UID is $UID" | tr -cd "[:digit:]/n"
OR
$ echo "My UID is $UID" | tr -d "a-zA-Z"

8. Here is an example of breaking a single line of words (sentence) into multiple lines, where each word appears in a separate line.

$ echo "My UID is $UID"

My UID is 1000

$ echo "My UID is $UID" | tr " "  "/n"

My 
UID 
is 
1000

9. Related to the previous example, you can also translate multiple lines of words into a single sentence as shown.

$ cat uid.txt

My 
UID 
is 
1000

$ tr "/n" " " < uid.txt

My UID is 1000

10. It is also possible to translate just a single character, for instance a space into a “ : ” character, as follows.

$ echo "Tecmint.com =>Linux-HowTos,Guides,Tutorials" | tr " " ":"

Tecmint.com:=>Linux-HowTos,Guides,Tutorials

There are several sequence characters you can use with tr, for more information, see the tr man page.

$ man tr

That’s all! tr is a useful command for manipulating text on the command line. In this guide, we showed some useful tr command usage examples for Linux newbies. You can share your thoughts with us via the comment form below.

Source: tecmint.com

Tags: Linux Commandslinux guidelinux vps setup guide
Previous Post

How to Set or Change System Hostname in Linux

Next Post

How to Get Domain and IP Address Information Using WHOIS Command

Next Post

How to Get Domain and IP Address Information Using WHOIS Command

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

No Result
View All Result

Recent Post

Install Imagemagick on CentOS
CentOS

Install Imagemagick on CentOS

by How VPS
June 28, 2023
0

This is how I installed Imagemagick on a vanilla CentOS server Start off by installing the prerequisites yum install php-pear...

Read more
how to Check phpinfo

How to Check phpinfo of Hosting or VPS?

June 28, 2023
Failed to download metadata for repo 'appstream' on Centos 8

How to fix error: Failed to download metadata for repo ‘appstream’ on Centos 8

February 25, 2022
How to Fix MySQL Error "Plugin 'InnoDB' registration as a STORAGE ENGINE failed"?

How to Fix MySQL Error “Plugin ‘InnoDB’ registration as a STORAGE ENGINE failed”?

November 17, 2020
How to optimize Mysql or MariaDB

How to optimize Mysql or MariaDB

November 3, 2020

Recent News

  • Install Imagemagick on CentOS
  • How to Check phpinfo of Hosting or VPS?
  • How to fix error: Failed to download metadata for repo ‘appstream’ on Centos 8

Category

  • Arch
  • Authentication
  • Backups
  • BSD
  • Centmin Mod
  • CentOS
  • Control Panels
  • CoreOS
  • CWP
  • Debian
  • Directadmin
  • Encryption
  • Fedora
  • Firewalls
  • Hocvps Script
  • Hosting providers
  • Kloxo-MR
  • Linux
  • Mitigations
  • Operating System
  • Plesk
  • Reviews
  • Securing VPS/Servers
  • Security Patches
  • SSL Certificates
  • Uncategorized
  • Upgrading
  • VPS/Servers management guides
  • Vulnerability Detection
  • Web servers software
  • Webhosting Control Panel
  • About
  • Advertise
  • Careers
  • Contact

© 2025 JNews - Premium WordPress news & magazine theme by Jegtheme.

No Result
View All Result
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon

© 2025 JNews - Premium WordPress news & magazine theme by Jegtheme.

Welcome Back!

Login to your account below

Forgotten Password?

Retrieve your password

Please enter your username or email address to reset your password.

Log In