trtranslation filter |
Command |
tr
[-cs
] string1 [string2]
tr
-s
[-c
]
string1 [string2]
tr
-d
[-c
]
string1
tr
-ds
[-c
]
string1 string2
tr
copies data read from the standard input to the standard
output, substituting or deleting characters as specified by the options,
string1 and string2. string1 and string2 are
considered to be sets of characters. In its simplest form,
tr
translates each character in string1 into the
character at the corresponding position in string2.
-c
complements the set of characters specified by string1. This
means that tr
constructs a new set of characters,
consisting of all the characters not found in string1 and uses this
new set in place of string1.
-d
deletes input characters found in string1 from the output.
-s
checks for sequences of a string1 character repeated several
consecutive times. When this happens, tr
replaces the
sequence of repeated characters with one occurrence of the corresponding
character from string2; if string2 is not specified, the
sequence is replaced with one occurrence of the repeated character itself.
For example,
tr -s abc xyz
translates the input string aaaabccccb
into the output
string of xyzy
.
If you specify both the -d
and -s
options, you must specify both string1 and string2. In this
case, string1 contains the characters to be deleted while
string2 contains characters which are to have multiple consecutive
appearances replaced with one appearance of the character itself. For
example,
tr -ds a b
translates the input string abbbaaacbb
into the output
string bcb
.
The actions of the -s
option take place after all
other deletions and translations.
Any character not described by the conventions that follow represents itself.
\
oooAn octal representation of a character with a specific coded value. It can consist of one, two, or three octal digits.
\
characterThe \
(backslash) character is used as an escape to remove
the special meaning of character. It also introduces escape
sequences for non-printing characters, in the manner of C character
constants: \\
, \a
, \b
,
\f
, \n
, \r
, \t
and
\v
.
-
c2This represents all characters between characters c1 and
c2 (in the current locale's collating sequence) including the end
values. For example, a-z
represents all the lowercase letters
in the POSIX locale while A-Z
represents all that locale's
uppercase letters. One way to convert lowercase and uppercase is with the
following filter:
tr 'a-z' 'A-Z'
This is not, however, the recommended method; use the
[:
class:]
construct instead.
[
c*
n]
This represents n repeated occurrences of character c.
(If n has a leading zero, tr
assumes it is
octal; otherwise, it is assumed to be decimal.) You can omit the number
for the last character in a subset. This representation is only valid in
string2.
[:
class:]
This represents all characters that belong to the character class
class in the locale indicated by
LC_CTYPE
. When the class [:upper]
or [:lower:]
appears in string1 and the opposite class,
[:lower:]
or [:upper:]
appears in string2,
tr
uses the LC_CTYPE
tolower
or toupper
mappings in the same relative
positions. Classes other than [:upper:]
or
[:lower:]
cannot be used for character mappings in
string2, since the order of characters in a class is
unspecified.
[=
c=]
This represents all characters which belong to the same equivalence
class as the character c in the locale indicated by
LC_COLLATE
. Equivalence classes cannot be used
for character mappings in string2. Only internationalized versions
of tr
support this format.
creates a list of all words (strings of letters) found intr -cs "[:alpha:]" "[\n*]" <file1 >file2
file1
and
puts it in file2
. This is accomplished by replacing strings of one
or more non-alphabetic characters with a single newline.
0
Successful completion.
1
Failure because of unknown command line option, or too few arguments.
regexp