tr Linux Commands – Overview with Examples and FAQs

Introduction

The Linux command tr is a command-line utility used to translate or delete characters. It is a useful tool for manipulating strings and can be used to perform various text transformations. It can be used to convert uppercase to lowercase, delete specific characters, squeeze repeating characters, and more. It is a powerful tool for text processing and can be used to perform a variety of tasks.

Examples

tr is a command-line utility in Linux that is used to translate or delete characters. It can be used to perform a variety of text manipulation tasks such as changing case, deleting specific characters, and replacing characters with other characters.

Syntax:

tr [OPTION] SET1 [SET2]

Options:

-c : Complement the SET1
-d : Delete characters in SET1
-s : Squeeze multiple occurrences of characters in SET1
-t : Truncate SET1 to length of SET2

Examples:

1. To convert all lowercase characters to uppercase:

echo "hello world" | tr [a-z] [A-Z]

Output:

HELLO WORLD

2. To delete all vowels from a string:

echo "hello world" | tr -d [aeiou]

Output:

hll wrld
[ad_1]

[ad_2]

The tr command in Linux is used for translating or deleting characters. It can be used to perform a variety of text manipulation tasks, such as changing the case of letters, replacing characters, deleting characters, and more. The tr command is a useful tool for manipulating text in Linux.

The syntax for the tr command is as follows:

tr [OPTION] SET1 [SET2]

The SET1 and SET2 arguments are strings of characters. The tr command will replace each character in SET1 with the corresponding character in SET2. If SET2 is omitted, then the characters in SET1 will be deleted.

For example, the following command will replace all lowercase letters with uppercase letters:

tr a-z A-Z

The tr command can also be used to delete characters. For example, the following command will delete all lowercase letters:

tr a-z

The tr command can also be used to delete specific characters. For example, the following command will delete all spaces:

tr -d ' '

The tr command is a powerful tool for manipulating text in Linux. It can be used to perform a variety of text manipulation tasks, such as changing the case of letters, replacing characters, deleting characters, and more.

Jaspreet Singh Ghuman

Jaspreet Singh Ghuman

Jassweb.com/

Passionate Professional Blogger, Freelancer, WordPress Enthusiast, Digital Marketer, Web Developer, Server Operator, Networking Expert. Empowering online presence with diverse skills.

jassweb logo

Jassweb always keeps its services up-to-date with the latest trends in the market, providing its customers all over the world with high-end and easily extensible internet, intranet, and extranet products.

GSTIN is 03EGRPS4248R1ZD.

Contact
Jassweb, Rai Chak, Punjab, India. 143518
Item added to cart.
0 items - 0.00