tr
tr linux command cheatsheet by Thamizhiniyan C S
Introduction
Translate command(tr
) can help you in number of ways, ranging from changing character cases in a string to replacing characters in a string.
Syntax
tr [flags] [source]/[find]/[select] [destination]/[replace]/[change]
Important Flags
Flags | Description |
---|---|
| To delete a given set of characters |
| To concat source set with destination set(destination set comes first; t stands for truncate) |
| To replace the source set with the destination set(s stands for squeeze) |
| This is the REVERSE card in this game, for eg. If you specify -c with -d to delete a set of characters then it will delete the rest of the characters leaving the source set which we specified (c stands for complement; as in doing reverse of something) |
| all letters and digits |
| all letters |
| all horizontal whitespace |
| all control characters |
| all digits |
| all printable characters, not including space |
| all lower case letters |
| all printable characters, including space |
| all punctuation characters |
| all horizontal or vertical whitespace |
| all upper case letters |
| all hexadecimal digits |
| all characters which are equivalent to CHAR |
Examples
Commands | Description |
---|---|
| Convert every alphabetic character to upper case |
| Convert every alphabetic character to upper case |
| To view creds of a user which are in digits |
| To replace all parentheses ( ) with box brackets [ ] |
| To delete all the lowercase characters a-z |
| To replace all sequences of multiple spaces with just one space |
| Translates all the white-space characters to tabs |
| To remove all the digits from the string |
| To remove all characters except digits ( complement ) |
| Replaces all characters except |
| To put each word in a new line |
| To delete the blank lines simply squeeze the repetitive newline characters |
| To print each directory on a separate line from the PATH environment variable |
| Decrypt the Caesar cipher in the |
Last updated