The tr command

The tr command is a Linux utility for text processing, such as translating, deleting, or squeezing repeated characters, which is shown as follows:

    $ tr '[a-z]' '[A-Z]' < filename

This will translate the lowercase characters to uppercase:

    $ tr '|' '~' < emp.lst

This will squeeze multiple spaces into a single space:

    $ ls -l | tr -s " "

In this example, the -s option squeezes multiple contiguous occurrences of the character into a single char. Additionally, the -d option can remove characters.

Get Learning Linux Shell Scripting - Second Edition now with O’Reilly online learning.

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