Also known as tr.1, tr(1), /usr/bin/tr
command in Unix-like operating systems
Described at
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. Complement the set of values specified by string1 . See the EXTENDED DESCRIPTION section. Complement the set of characters specified by string1 . See the EXTENDED DESCRIPTION section. Delete all occurrences of input characters that are specified by string1 . Replace instances of repeated characters with a single character, as described in the EXTENDED DESCRIPTION section. 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. Provide a default value for the internationalization variables that are unset or null. (See XBD Internationalization Variables for the precedence of internationalization variables used to determine the values of locale categories.) If set to a non-empty string value, override the values of all the other internationalization variables. Determine the locale for the behavior of range expressions and equivalence classes. Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error. [XSI) ] ![[Option Start]]( Determine the location of message catalogs for the processing of LC MESSAGES. ![[Option End]]( The tr output shall be identical to the input, with the exception of the specified transformations. 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. Any character not described by one of the conventions below shall represent itself. Octal sequences can be used to represent characters with specific coded values. An octal sequence shall consist of a 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. Multi-byte characters require multiple, concatenated escape sequences of this type, including the leading for each byte. 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. 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 : If the name specified for class does not define a valid character class in the current locale, the behavior is undefined. Input characters found in the array specified by string1 shall be deleted. The same string cannot be used for both the -d and the -s option; when both options are specified, both string1 (used for deletion) and string2 (used for squeezing) shall be required. When the -s option is specified, after any deletions or translations have taken place, repeated sequences of the same character shall be replaced by one occurrence of the same character, if the character is found in the array specified by the last operand. If the last operand contains a character class, such as the following example: the last operand's array shall contain all of the characters in that character class. However, in a case conversion, as described previously, such as: the last operand's array shall contain only those characters defined as the second characters in each of the toupper or tolo
Excerpt from a page describing this subject · 20,993 chars · not written by Vinony
Wikidata facts
- Part of
- GNU Core Utilities
- Image
- Tr Unix.png
Show 3 more facts
- source code repository URL
- openbsd.su/src/usr.bin/tr
- described at URL
- pubs.opengroup.org/onlinepubs/9699919799/utilities/tr.html
- has command line option
- s
via Wikidata · CC0
Article · 中文
tr是一个类Unix操作系统中的命令。它是translate或transliterate的缩写,表示替换或删除输入数据集中特定字符。 该程序从其标准输入中读取一个字节流,并将结果写入标准输出。需要两组字符(通常长度相同),并用第二组中的相应元素替换第一组中的字符。例如, tr 'abcd' 'jkmn' 将a映射到j,b到k,c到m,d到n。 字符集可以使用字符范围缩写。前面的例子可以写成: tr 'a-d' 'jkmn' 在兼容POSIX标准的tr版本中,字符范围集合取决于的,所以在脚本中避免使用字符范围可能更安全,因为脚本可能会在与编写时不同的语言环境下执行。范围通常可以用POSIX字符集替换,例如[:alpha:]。 s标志使tr将其输出中相同相邻字符的序列压缩为单个字符。例如, tr -s ' ' 用一个换行符替换连续的一个或多个换行符。 d标志使tr从其输入中删除指定的一组字符。在这种情况下,只使用单个字符集参数。以下命令删除回车符。 tr -d '' c标志表示第一组字符的补。调用 tr -cd '[:alnum:]' 会删除所有非字母或数字字符。 tr的大多数版本,包括GNU tr和经典的Unix tr,都以单字节字符操作,不兼容Unicode。的实现是个例外,它提供了基本的Unicode支持。 Ruby和Perl也有一个内置的tr操作符,使用方法类似。Tcl的string map命令更加通用,因为它将字符串映射到字符串,而tr将字符映射到字符。
Abstract from DBpedia / Wikipedia · CC BY-SA