O'Reilly logo

Linux Shell Scripting Essentials by Sinny Kumari

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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:

Option

Description

-c, -C

Use complement of SET1

-d

This deletes a range of characters specified in SET1.

-s

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

-t

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required