12.1. About tr

Tr is a utility that lets you translate characters by substitution or deletion from standard input. Tr is used mainly for stripping off control characters from files or doing character case conversions. When you use tr you generally pass it two strings: string1 is what you are searching for and string2 is what you want done with the translation. When tr is initially invoked, the characters in string1 are mapped across into the characters of string2; the conversion will then begin.

In this chapter we will cover:

  • converting lower to upper case;

  • stripping files of control characters; and

  • deleting blank lines.

The formats of the tr command with its most used options are:

tr -c -d -s ["string1_to_translate_from"] ["string2_to_translate_to"] input_file ...

Get Linux and Unix Shell Programming now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.