O'Reilly logo

Practical UNIX by Steve Moritsugu - DTR Business Systems

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

Replacing/Removing Characters in a File or Pipeline

The tr command enables you to translate every occurrence of one specific character into a different character. It also enables you to delete every occurrence of a specific character. tr does not allow any files on the command line, so you must pipe any data for tr to translate.

Determining Which Type of tr Is on Your UNIX System

Unfortunately, there are two different versions of tr. They differ in whether they require brackets [ ] around ranges of characters. Some versions of UNIX have one type of tr; other versions have a different type of tr.

This is how the nonbracket version of tr works:

$ echo abcdefaabbcc | tr 'a-c' '1-3'
123def112233
$

In this command, echo sends the letters abcdefaabbcc ...

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