tr copies data read from the standard input
to the standard output (unless the
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.
deletes input characters found in string1 from the output.
specifies an input file to be read instead of the standard input.
specifies an output file to be written to instead of the standard output.
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
-dand -soptions, 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
-soption take place after all other deletions and translations.
You can use the following conventions to represent elements of string1 and string2.
Any character not described by the conventions that follow represents itself.
An octal representation of a character with a specific coded value. It can consist of one, two, or three octal digits.
The \ (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.
This 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.
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.
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.
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.
tr -cs "[:alpha:]" "[\n*]" <file1 >file2
creates a list of all words (strings of letters) found in file1 and puts it in file2. This is accomplished by replacing strings of one or more non-alphabetic characters with a single newline.
Possible exit status values are:
POSIX.2. x/OPEN Portability Guide 4.0. Windows 7. Windows Server 2008 R2. Windows 8. Windows Server 2012. Windows 10. Windows Server 2016. Windows Server 2019.
Backwardly compatible with both the UNIX Version 7 and System V variants of this command, but with extensions (C escapes, handles ASCII NUL, internationalization).
PTC MKS Toolkit for Power Users
PTC MKS Toolkit for System Administrators
PTC MKS Toolkit for Developers
PTC MKS Toolkit for Interoperability
PTC MKS Toolkit for Professional Developers
PTC MKS Toolkit for Professional Developers 64-Bit Edition
PTC MKS Toolkit for Enterprise Developers
PTC MKS Toolkit for Enterprise Developers 64-Bit Edition
PTC MKS Toolkit 10.2 Documentation Build 28.