Linux tr
The command ‘tr’ stands for ‘translate’. It is used to translate, like from lowercase to uppercase and vice versa or new lines into spaces.
Syntax:
Change Case
The ‘tr’ command can change case.
Syntax:
Example:
Look at the above snapshot, all p,r,c,u are converted into upprecase P,R,C,U.
Remove New Lines
To write all the lines into a single line we have to translate all new lines into spaces.
Syntax:
Example:
tr Options
- tr -s : The ‘tr -s’ command squeezes the occurence of multiple characters into one.
- tr rot13: This command encrypts the text. It is case-sensitive.
- tr -d: The ‘tr -d’ command is used to delete characters.
Syntax:
Example:
Look at the above snapshot, command “cat jtp.txt | tr -s ‘l'” has squeezed all the letters ‘l’ into one and command “cat spaces.txt | tr -s ‘ ‘” has squeezed all the spaces into single space.
Example:
Look at the above snapshot, all the letters are encrypted according to the command. But letter ‘A’ and ‘M’ are not encrypted as they are in upper case.
Syntax:
Example:
Look at the above snapshot, all the ‘o’ letters are deleted from the file ‘exm.txt’.