tr
ShellFundamentals In simulator In real LinuxTranslate or delete characters
Name: tr = translate
You can practise it right away in the simulator, and use it in real Linux mode too.
Description
tr reads standard input and replaces each character of set 1 with the matching character of set 2; -d deletes characters and -s squeezes repeats into one.
tr only reads standard input and takes no file names, so you write cat file | tr ... or tr ... < file.
Syntax
tr [OPTION]... SET1 [SET2]Common options
| a-z | A character range; classes like [:upper:] [:digit:] work too |
| [:lower:] / [:upper:] / [:digit:] / [:space:] | Character classes: lower case, upper case, digits, white space, e.g. tr '[:lower:]' '[:upper:]' |
| -d / --delete | Delete characters in SET1 |
| -s / --squeeze-repeats | Squeeze repeated characters into one |
| -c / --complement | Use the characters not in the set, e.g. tr -cd '0-9' keeps only digits |