Ad space (banner)
🖥️Linux Lessons
Lesson 44 / 61

Replacing Characters with tr

tr is for when "I want to replace a specific character in a string with a different one." tr stands for translate, and it converts input character by character into different characters.

Use it in the form tr from-characters to-characters, typically combined with standard input or a pipe. It also supports ranges, like a-z.

Running tr a-z A-Z notes.txt displays the contents of notes.txt with every lowercase letter converted to uppercase.

A common early mistake is confusing this with sedtr only converts single characters; it doesn't support pattern replacement for words or multi-character strings.

In real work, this is used for simple character-conversion tasks — converting line-ending characters, or turning a CSV's comma delimiter into a tab.

Linux
Try it (type this into the pseudo terminal)
tr a-z A-Z notes.txt

🧑‍💻 You can type this command into the Linux pseudo terminal to try it yourself (this page itself has no interactive terminal).

Ad space (banner)
Ad space (in-article)