Spent 2 hours to write a document or a program but wrote a ‘name’ or a ‘keyword’ wrong every time you used it. What to do now? It must be your ‘karma’ hitting back at you ,wanting you to go through whole text again and replace those words. But you have a life, and here ‘tr’ command becomes the life-saver.
‘tr’ as the name suggests is for translation of some set of characters into some other set of characters.The general syntax of tr is:
tr [options] set1 [set2]
The items in the square brackets are optional. tr requires at least one argument and accepts a maximum of two.
Using without any options, tr will replace the characters provided in set1 with those provided in set2. Thus, for example, every instance of the letter a in text typed in at the keyboard can be replaced with the letter b by entering the following command, press ENTER,type the text, and then again press the ENTER key:
tr a b
We can also input our file with input redirection operator.
tr a b < file1
Multiple characters can also be translated by listing the characters that are to be changed in the first argument and and listing their respective replacements in order in the second argument.
tr ‘[efg]’ ‘[xyz]’ < file1