Book Image

Linux Shell Scripting Essentials

By : Sinny Kumari, Khem Raj
Book Image

Linux Shell Scripting Essentials

By: Sinny Kumari, Khem Raj

Overview of this book

Table of Contents (15 chapters)
Linux Shell Scripting Essentials
About the Author
About the Reviewers

Character-based translation using tr

Another interesting shell command is tr. This translates, squeezes, or deletes characters from the standard input. The syntax will be as follows:

tr [OPTION]... SET1 [SET2]

The options for the tr commands are explained in the following table:



-c, -C

Use complement of SET1


This deletes a range of characters specified in SET1.


This replaces consecutive multiple occurrences of characters in SET1 with a single occurrence.


This truncates SET1 to the length of SET2. Any extra characters in SET1 will be not considered for translation.

SETs are a string of characters that can be specified using the following:

  • A character class: [:alnum:], [:digit:], [:alpha:] and so on

  • A character range: 'a-z', 'A-Z', and '0-9'

  • An escape character: \\, \b, \r, \n, \f, \v, and \t

To provide an input text from a file and an output to a file, we can use the file redirection operators: < (less than for input) and > (greater than for...