tr command in Linux (transforms text)
The tr command in Linux replaces one variable with another specified one. This command does not work directly with files, so it should be used with the standard output of another command, with the pipe conductor.
The tr command can swap characters from the search variable to the swap variable, but the number of characters must be the same in both.
The most common options are:
- -d: Delete occurrences of the search variable;
- -s: Suppress repeated occurrences of the search variable;
Take the example with the grocery list, where tr is used to change all lowercase letters to uppercase letters:
The tr command can be useful for transforming spaces for TABS into a file:
You can also fix text by removing spaces:
It can also remove repeated characters:
www.certificacaolinux.com.br www.kernel.org www.nic.br It can also be used to replace Return “ n” with a comma:
You can also do the opposite by transforming a file with items separated by commas into lines:
Resistance Watch a video of how this command works:
Learn much more about Linux in our online course. You can register here. If you already have an account, or want to create one, just log in or create your user here.
Did you like it?
Share