tr
tr
Purpose
Copies from standard input to standard output, while substituting one set of characters with another.
Syntax
tr [options]
string1
[
string2
]
Options
-c
complements characters in string1
with ASCII codes 001-377.
-d
deletes from the input all characters specified in string1.
-s
replaces repeated sequences of any character in string1
with a single character.
Description
The tr
command substitutes all characters in string1
in the input with the corresponding characters in string2
. For example, to convert the file sample.lc
to all uppercase and store in sample.uc
, type the following:
tr [a-z] [A-Z]
< sample.lc
> sample.uc
To replace repeated occurrences of newlines in a file with a single newline character, type the following:
tr -s '\n'
< infile
> outfile