tr

NAME

tr - Windows command-line utility to write the translated input characters from standard input to standard output

SYNOPSIS

tr [-cs] string1 string2

tr -s [-c] string1

tr -d [-c] string1	

tr -ds [-c] string1 string2

DESCRIPTION

The tr(1w) Windows utility copies the standard input to the standard output with substitution or deletion of the selected characters. The specified options, and the string1 and string2 operands control translations that occur while copying characters and single-character collating elements.

The operands string1 and string2 (if specified) define two arrays of characters. You can use the constructs in the following list to specify characters or single-character collating elements. If any of the constructs result in multicharacter collating elements, tr excludes, without a diagnostic, those multicharacter elements from the resulting array.

character
Any character not described by one of the following conventions represents itself.
\octal
Octal sequences can be used to represent characters with specific coded values. An octal sequence consists of a backslash (\) followed by the longest sequence of octal characters (01234567). The sequence causes the character whose encoding is represented by an octal integer to be placed into the array.
\character
The backslash-escape sequences supported are \\, \a, \b, \f, \n, \r, \t, and \v. The results of using any other character (other than an octal digit) following the backslash are unspecified.
c-c
Represents the range of collating elements between the range endpoints, inclusive, as defined by the current setting of the LC_COLLATE locale category. The starting endpoint must precede the second endpoint in the current collation order. The characters or collating elements in the range are placed in the array in ascending collation sequence.
[:class:]

Represents all characters belonging to the defined character class, as defined by the current setting of the LC_CTYPE locale category. The following character class names are accepted when specified in string1:

In addition, character class expressions of the form [:name:] are recognized in those locales where the name keyword has been given a charclass definition in the LC_CTYPE category. When both the -d and -s options are specified, any of the character class names will be accepted in string2. Otherwise, only character class names lower or upper are valid in string2, and then only if the corresponding character class (upper and lower, respectively) is specified in the same relative position in string1. Such a specification is interpreted as a request for case conversion.

When [:lower:] appears in string1 and [:upper:] appears in string2, the arrays will contain the characters from the toupper mapping in the LC_CTYPE category of the current locale. When [:upper:] appears in string1 and [:lower:] appears in string2, the arrays contain the characters from the tolower mapping in the LC_CTYPE category of the current locale. The first character from each mapping pair will be in the array for string1, and the second character from each mapping pair will be in the array for string2 in the same relative position.

Except for case conversion, the characters specified by a character class expression are placed in the array in an unspecified order. If the name specified for the class does not define a valid character class in the current locale, the behavior is undefined.

[=equiv=]
Represents all characters or collating elements belonging to the same equivalence class as equiv, as defined by the current setting of the LC_COLLATE locale category. When equiv is used with the combined -d and -s options, an equivalence class expression is allowed only in string1 or string2. The characters belonging to the equivalence class are placed in the array in an unspecified order.
[x*n]
Represents n repeated occurrences of the character x. Because this expression is used to map multiple characters to one, it is valid only when it occurs in string2. If n is zero or omitted, it is interpreted as large enough to extend the string2-based sequence to the length of the string1-based sequence. If n has a leading zero, it is interpreted as an octal value. Otherwise, it is interpreted as a decimal value.

OPTIONS

The tr utility supports the following options:

No option
When tr is invoked without any options, and with two operands string1 and string2, each input character found in the array specified by string1 is replaced by the character in the same relative position in the array specified by string2. When the array specified by string2 is shorter than the one specified by string1, the results are unspecified.
-cs
When tr is invoked with operands string1 and string2, each input character not found in the array specified by string1 is replaced by the character specified by string2. The repeated sequences of the character found in string2 are then replaced by one occurrence of the same character. The string2 should be of type [x*n]. If string2 is not of type [x*n], it is neglected and behaves as if only one operand is specified.
-s
When tr is invoked with only one operand string1, repeated sequences of the same character not found in the array string1 are replaced by one occurrence of the same character. When tr is invoked with operands string1 and string2, each input character found in the array specified by string1 is replaced by the character in the same relative position in the array specified by string2. Then the repeated sequences of the same character found in the array string2 are replaced by one occurrence of the same character.
-d
When tr is invoked with only one operand string1, the repeated sequences of the same character found in the array string1 are replaced by one occurrence of the same character.
-cd
When tr is invoked with only one operand string1, all input characters except those specified by string1 are deleted.
-ds
When tr is invoked with operands string1 and string2, input characters found in the array specified by string1 are deleted. Then the repeated sequences of the same character found in the array string2 are replaced by one occurrence of the same character.
-dsc
When tr is invoked with operands string1 and string2, input characters not found in the array specified by string1 are deleted. Then the repeated sequences of the same character found in the array string2 are replaced by one occurrence of the same character.

ARGUMENTS

The tr utility supports the following arguments:

string1, string2
Translation control strings. Each string represents a set of characters to be converted into an array of characters used for the translation.

DIAGNOSTICS

Possible exit-status values are:

0
Successful completion
1
Failure

EXAMPLES

tr -cs "[:alpha:]" "[\n*]"; <file1> <file2>

Creates a list of all words in file1 one per line in file2, where a word is taken to be a maximal string of letters.

tr "[:lower:]" "[:upper:]" <file1>

Translates all lowercase characters in file1 to uppercase and writes the results to the standard output.

tr "[=<e>=]" <e> <file1> <file2>

Uses an equivalence class to identify accented variants of the base character e in file1, which are stripped of diacritical marks and written to file2.