Warning: main(/www/www/htdocs/style/globals.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/utilities/t/tr.html on line 1
Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/globals.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/utilities/t/tr.html on line 1
Warning: main(/www/www/htdocs/style/header.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/utilities/t/tr.html on line 8
Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/header.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/utilities/t/tr.html on line 8
Translate characters (POSIX)
tr [-cs] [-r filename] string1 string2
tr [-cs] [-r filename] string1
tr -d [-c] [-r filename] string1
tr -ds [-c] [-r filename] string1 string2
QNX Neutrino, Microsoft Windows
- -c
- Complement the set of characters in string1 with
respect to the universe of characters from 00 through FF hex.
Characters in string1 are copied unchanged while
all other characters are translated.
- -d
- Delete all input characters in string1 (or not in
string1 for -dc).
- -r filename
- (QNX Neutrino extension) Translate the named file in place (don't use stdin/stdout).
- -s
- Squeeze all output strings of one or more instances of a single character
in string1 to a single instance of the corresponding character
in string2.
If you don't specify string2, tr squeezes instances
of the characters in string1 to a single instance of that
character.
- string1
- Translation character string (translate from).
- string2
- Translation character string (translate to).
|
If you specify both -d and -s, tr
deletes instances of the characters in string1 and squeezes
instances of the characters in string2 (i.e. tr
doesn't translate in this case). |
The tr utility copies the standard input to the standard
output with substitution or deletion of selected characters. The options
specified and the string1 and
string2 operands control translations that occur
while copying characters.
The default behavior is to replace each input character found in
string1 with the character at the same position in
string2, while copying characters not in
string1 unchanged.
When string2 is shorter than
string1, string2 is extended to
the length of string1 by duplicating the last character
of string2. If string2 is
explicitly a string of zero length, it's padded with NUL
characters.
|
The string1 and string2 operands
often require quoting to avoid interpretation by the shell. Single quotes are
usually the proper quoting mechanism. |
Use the following conventions in string1 or
string2 or both to specify characters, character
ranges, character classes, or collating elements:
- character
- Represents that character.
- \octal
- A backslash followed by 1, 2, or 3 octal digits represents a character
with that encoded value.
- \character
- A backslash followed by any character except an octal digit represents
that character.
- c-c
- Represents the range of characters between the range endpoints, inclusive.
- [c-c]
- (QNX Neutrino extension) The System V method of representing a range
of characters.
- [:class:]
- Represents all characters belonging to the defined character class.
Allowable names for class are:
alnum,
alpha,
blank,
cntrl,
digit,
graph,
lower,
print,
punct,
space,
upper,
xdigit
- [.cs.]
- Represents a collating symbol. Multicharacter collating symbols must
be represented as collating symbols to distinguish them from a
string of the same characters. This implementation allows an
arbitrary string to be treated as a collating symbol (QNX Neutrino extension).
- [x*n]
- Represents n repeated occurrences of the character
or collating symbol x. This expression is valid
only in string2. If n is
omitted or is zero, it's 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's interpreted as an octal
value. Otherwise, it's interpreted as a decimal value.
Convert all lowercase characters in the input to
the corresponding uppercase characters:
tr '[:lower:]' '[:upper:]' <file1 >file2
Or
tr '[a-z]' '[A-Z]' <file1 >file2
Create a list of all words in file1
one per line in file2 where a word is taken to be a maximal
string of letters (octal 012 is the code for newline):
tr -cs '[:alpha:]' '[\012*]' <file 1 >file2
Convert a DOS file into a UNIX file:
tr -d '\15' <infile >outfile
- 0
- Success
- 1
- An error occurred.
gawk,
sed,
textto
Warning: main(/www/www/htdocs/style/footer.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/utilities/t/tr.html on line 292
Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/footer.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/utilities/t/tr.html on line 292