Table of Contents
tr - translate characters
tr [-c | -C][-s] string1 string2
tr -s [-c | -C] string1
tr -d [-c | -C] string1
tr -ds [-c | -C] string1 string2
The tr utility shall copy the standard input to the standard
output with substitution or deletion of selected characters. The options
specified and the string1 and string2 operands shall control translations
that occur while copying characters and single-character collating elements.
The tr utility shall conform to the Base Definitions volume of IEEE
Std 1003.1-2001, Section 12.2, Utility Syntax Guidelines.
The following options
shall be supported:
- -c
- Complement the set of values specified by string1.
See the EXTENDED DESCRIPTION section.
- -C
- Complement the set of characters
specified by string1. See the EXTENDED DESCRIPTION section.
- -d
- Delete all
occurrences of input characters that are specified by string1.
- -s
- Replace
instances of repeated characters with a single character, as described
in the EXTENDED DESCRIPTION section.
The following operands shall
be supported:
- string1, string2
Translation control strings. Each string
shall represent a set of characters to be converted into an array of characters
used for the translation. For a detailed description of how the strings
are interpreted, see the EXTENDED DESCRIPTION section.
The standard
input can be any type of file.
None.
The
following environment variables shall affect the execution of tr:
- LANG
- Provide a default value for the internationalization variables that are
unset or null. (See the Base Definitions volume of IEEE Std 1003.1-2001, Section
8.2, Internationalization Variables for the precedence of internationalization
variables used to determine the values of locale categories.)
- LC_ALL
- If
set to a non-empty string value, override the values of all the other internationalization
variables.
- LC_COLLATE
Determine the locale for the behavior of range expressions
and equivalence classes.
- LC_CTYPE
- Determine the locale for the interpretation
of sequences of bytes of text data as characters (for example, single-byte
as opposed to multi-byte characters in arguments) and the behavior of character
classes.
- LC_MESSAGES
- Determine the locale that should be used to affect
the format and contents of diagnostic messages written to standard error.
- NLSPATH
- Determine the location of message catalogs for the processing of
LC_MESSAGES .
Default.
The tr output shall be identical
to the input, with the exception of the specified transformations.
The
standard error shall be used only for diagnostic messages.
None.
The operands string1 and string2 (if specified) define
two arrays of characters. The constructs in the following list can be used
to specify characters or single-character collating elements. If any of the
constructs result in multi-character collating elements, tr shall exclude,
without a diagnostic, those multi-character elements from the resulting
array.
- character
- Any character not described by one of the conventions below
shall represent itself.
- \octal
- Octal sequences can be used to represent characters
with specific coded values. An octal sequence shall consist of a backslash
followed by the longest sequence of one, two, or three-octal-digit characters
(01234567). The sequence shall cause the value whose encoding is represented
by the one, two, or three-digit octal integer to be placed into the array.
If the size of a byte on the system is greater than nine bits, the valid
escape sequence used to represent a byte is implementation-defined. Multi-byte
characters require multiple, concatenated escape sequences of this type,
including the leading ’\’ for each byte.
- \character
- The backslash-escape sequences
in the Base Definitions volume of IEEE Std 1003.1-2001, Table 5-1, Escape
Sequences and Associated Actions ( ’\\’ , ’\a’ , ’\b’ , ’\f’ , ’\n’ , ’\r’ , ’\t’ , ’\v’ ) shall
be supported. The results of using any other character, other than an octal
digit, following the backslash are unspecified.
- c-c
- In the POSIX locale,
this construct shall represent the range of collating elements between
the range endpoints (as long as neither endpoint is an octal sequence of
the form \octal), inclusive, as defined by the collation sequence. The characters
or collating elements in the range shall be placed in the array in ascending
collation sequence. If the second endpoint precedes the starting endpoint
in the collation sequence, it is unspecified whether the range of collating
elements is empty, or this construct is treated as invalid. In locales other
than the POSIX locale, this construct has unspecified behavior.
If either
or both of the range endpoints are octal sequences of the form \octal, this
shall represent the range of specific coded values between the two range
endpoints, inclusive.
- :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 shall be accepted when
specified in string1:
In addition, character class expressions of the
form [: name:] |
shall be recognized in those locales where the name |
- =equiv=
- x*n
Table of Contents