Translating with tr

tr is a small and beautiful command in the Unix command-warrior toolkit. It is one of the important commands frequently used to craft beautiful one-liner commands. It can be used to perform substitution of characters, deletion of the characters, and squeezing of repeated characters from the standard input. It is often called translate , since it can translate a set of characters to another set. In this recipe we will see how to use tr to perform basic translation between sets.

Getting ready

tr accepts input only through stdin (standard input) and cannot accept input through command-line arguments. It has the following invocation format:

tr [options] set1 set2

Input characters from stdin are mapped from set1 to set2 and the output ...

Get Linux Shell Scripting Cookbook - Second Edition 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.