Linux tr Command Tutorial With Examples

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/linux-tr-command-tutorial-examples/
PINTEREST
PINTEREST
INSTAGRAM

tr is mainly used to translate or delete characters in bash. tr is not a complex but useful command. We will look various usage scenarios  of tr in this tutorial.

Syntax

Help

Help can be get with --help parameter like below.

Help

Help

Man

Man page of tr can be also viewed like below.

Man

Man

Convert Lowercase To Uppercase

One of the most popular usage of tr is converting texts from lowercase to uppercase.

Convert Lower Case To Upper Case

Convert Lowercase To Uppercase

Convert Uppercase To Lowercase

Reverse application of Lowercase to uppercase is uppercase to lowercase. This can be implemented with the command below.

OR

Convert Upper Case To Lower Case

Convert Uppercase To Lowercase

Translate Braces To Parenthesis

We can translate braces into parenthesis like below. This can be applied other characters too.

Translate Braces To Parenthesis

Translate Braces To Parenthesis

Translate White-space To Tabs

White spaces can be expressed like below and translated to the tabs with the following command.

Delete Specified Characters

Another useful feature is deleting specified characters from the given text. The character that will be deleted is specified with -d parameter like below.

Delete Specified Characters

Delete Specified Characters

Complement Characters

The filtering is another feature of tr. Only Specified characters can be printed like below. In this example we will only print numbers or digits with the following command.

LEARN MORE  Linux fdisk Tutorial With Examples

Complement Characters

Complement Characters

Remove All Non-printable Characters

Non-printable characters can be removed with the following command with-cd [:print:]

Remove All Non-printable Characters

Remove All Non-printable Characters

Join Multiple Line Into Single

Following command will translate line endings into  spaces and make the whole multi line text a single line text.

Join Multiple Line Into Single

Join Multiple Line Into Single

Expressions

All supported expressions can be found below.

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/linux-tr-command-tutorial-examples/
PINTEREST
PINTEREST
INSTAGRAM

You may also like...

1 Response

Leave a Reply

Your email address will not be published.

Enjoy this blog? Please spread the word :)