The term TR stands for translate, using this TR command we can translate, squeeze, replace or delete the strings or characters from standard input, writing to standard output.
TR command translates uppercase to lower case, squeezing repeating pattern strings or characters and deletes the characters, the translate command doesn’t take any file name if you want to supply file name then it can only be supplied using input re-directional operator.
We are going to discuss how tr command works in Linux and Unix operating systems with simple examples.
TR command syntax
tr [OPTION]... SET1 [SET2]
TR convert lowercase letters to upper case letters
$cat techdiip | tr “[a-z]” “[A-Z]”
Output
TECHDIIP
There is another way one can also try this.
$cat techdiip | tr “[:lower:]” “[:upper:]”
Output
TECHDIIP
TR command to convert upper case with a file
$cat techdiip.txt
i love powershell scripting
i’m learning powershell
i teach powershell
$cat techdiip.txt | tr “[:lower:]” “[:upper:]”
output
I LOVE POWERSHELL SCRIPTING
I’M LEARNING POWERSHELL
I TEACH POWERSHELL
TR delete a specified character
$ echo "Teach Powershell Basics" | tr -d 'T'
Output
each Powershell Basics
In the above example character T has been removed.
TR command Delete numbers
$ echo "Password number 143143" | tr -d [:digit:]
Output
Password number
In Linux sets as declared as strings of characters, few of them can be used as SET1 or SET2
TR breaking line of text to multiple lines
$each "I'm Learning TR commands in Linux " | tr " " "/n"
output
I'm
Learning
TR
commands
in
Linux
Backslash escapes |
\a | audible |
\b | backspace |
\r | return |
\t | horizontal |
\f | form feed |
\n | new line |
\v | vertical |
TR command parameters to perform Character operations |
c, -c | text complement |
-t | truncate |
-help | gives you the help information |
-version | gives you version information |
-s | squeezes the repeated charectors |
[:print:] | all printable characters, including space |
Other TR commands |
[:blank:] | This parameter used in syntax for horizontal whitespace |
[:upper:] | This parameter used in syntax for upper case letters |
[:xdigit:] | This parameter used in syntax for hexadecimal digits |
[:cntrl:] | This parameter used in syntax for control characters |
[:digit:] | This parameter used in syntax forl digits in Lunix |
Thank you for visiting my site, for any scripts and commands in these articles you are testing please make sure you have tested this script in your lower environment before you run in production.
I hope you find this article useful if you have any questions please let us know.
Leave a Reply Cancel reply