How can the tr command be used to translate characters?

You can use the tr command to translate characters by specifying two sets of characters: the first set (SET1) contains the characters you want to replace, and the second set (SET2) contains the characters you want to use as replacements.

Syntax:

tr SET1 SET2

Example:

To convert lowercase letters to uppercase, you can use the following command:

echo "hello labex" | tr '[:lower:]' '[:upper:]'

Explanation:

  • echo "hello labex" generates the input string.
  • The tr '[:lower:]' '[:upper:]' command translates all lowercase letters in the input to their uppercase counterparts.

Output:

HELLO LABEX

This command effectively transforms the input text by replacing each lowercase letter with its uppercase equivalent.

0 Comments

no data
Be the first to share your comment!