Translate/tr command in unix

Tr is a command in Unix.It is an abbreviation of translate or transliterate, indicating its operation of replacing or removing specific characters in its input data set.The utility reads a byte stream from its standard input and writes the result to the standard output. As arguments, it takes two sets of characters (generally of the same length), and replaces occurrences of the characters in the first set with the corresponding elements from the second set.
The syntax for the Tr command is  

The options are
  • -c : complements the set of characters in string.
  • -d : deletes the characters in set1
  • -s : replaces repeated characters listed in the set1 with single occurrence
  • -t : truncates set1
Examples for Tr command 
Consider below text used as example
                                                 unix os                                                                
  • Convert lower case letters to upper case
                       > echo "unix os" | tr "[:lower]" "[:upper]"                            
                                                UNIX OS                                                               
  • Delete non printable characters
         The -d option can be used to delete characters. The following example deletes all the non-                printable characters from a file. 
                                     > tr  -cd  "[:print]" < filename                                         

Powered by Blogger.