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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.