Linux Command - tr

tr - Translate characters.

Translate, squeeze, and/or delete characters from standard input, writing to standard output.

Syntax

1
tr [OPTIONS] SET1 [SET2]

Options

Common Option Description
-c use the complement of SET1
-d delete characters in the first set
-s replace each input sequence of a repeated character that is listed in SET1 with a single occurrence of that character
-t first truncate SET1 to length of SET2

Examples

Replace characters

1
tr 'abc' 'DEF' < file1

Here we replace ‘a’ with ‘D’, ‘b’ with ‘E’ and ‘c’ with ‘F’.

Remove Characters

1
tr -d 'ac' < file1

Remove character ‘a’ and ‘c’

Compress Characters

1
tr -s '[:blank:]' < file1

Blanks will be compressed. e.g. ‘ab cd’ will become ‘ab cd’

Lower case to upper case

1
tr '[:lower:]' '[:upper:]' < file1

Reference