Forrest logo
back to the echo tool

tr:tldr:3b86a

tr: Replace all occurrences of a character from another command's output.
$ echo ${text} | tr ${find_character} ${replace_character}
try on your machine

This command is used to replace a specific character in a string or text with another character. Let's break down the command:

  • echo ${text}: This part outputs the value of the variable ${text}. The variable ${text} should be assigned a string or a text that you want to modify.
  • |: This is called the pipe operator and it is used to redirect the output of the preceding command to the input of the succeeding command.
  • tr ${find_character} ${replace_character}: This part uses the tr command to perform the character replacement. The variable ${find_character} should contain the character you want to find, and the variable ${replace_character} should contain the character you want to replace it with.

To give an example, let's say we have the following command:

echo "Hello, world!" | tr o e

This command will replace all occurrences of the letter 'o' with the letter 'e' in the string "Hello, world!". So, the output of this command would be:

Hello, werld!

Note that the tr command only replaces single characters, not multiple characters or substrings.

This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.
back to the echo tool