请输入您要查询的百科知识:

 

词条 Tr (Unix)
释义

  1. Overview

  2. Implementations

  3. See also

  4. References

  5. External links

{{lowercase}}{{Infobox Software
| name = tr
| logo =
| screenshot = Tr Unix.png
| screenshot size =
| caption = The {{code|tr}} command
| author =
| developer = AT&T Bell Laboratories
| released = {{Start date and age|1973|11}}
| latest release version =
| latest release date =
| operating system = Unix and Unix-like, OS-9
| genre = Command
| license = coreutils: GNU GPL v3
| website =
}}

tr is a command in Unix and Unix-like operating systems. It is an abbreviation of translate or transliterate, indicating its operation of replacing or removing specific characters in its input data set.

Overview

The utility reads a byte stream from its standard input and writes the result to the standard output. As arguments, it takes two sets of characters (generally of the same length), and replaces occurrences of the characters in the first set with the corresponding elements from the second set. For example,

maps all characters a to j, b to k, c to m, and d to n.

The character set may be abbreviated by using character ranges. The previous example could be written:

In POSIX-compliant versions of tr, the set represented by a character range depends on the locale's collating order, so it is safer to avoid character ranges in scripts that might be executed in a locale different from that in which they were written. Ranges can often be replaced with POSIX character sets such as [:alpha:].

The s flag causes tr to compress sequences of identical adjacent characters in its output to a single token. For example,

replaces sequences of one or more newline characters with a single newline.

The d flag causes tr to delete all tokens of the specified set of characters from its input. In this case, only a single character set argument is used. The following command removes carriage return characters.

The c flag indicates the complement of the first set of characters. The invocation

therefore removes all non-alphanumeric characters.

Implementations

The version of tr bundled in GNU coreutils was written by Jim Meyering.[1]

The command is also available in the OS-9 shell.[2]

Most versions of tr, including GNU tr and classic Unix tr, operate on single-byte characters and are not Unicode compliant. An exception is the Heirloom Toolchest implementation, which provides basic Unicode support.

Ruby and Perl also have an internal tr operator, which operates analogously.[3][4] Tcl's string map command is more general in that it maps strings to strings while tr maps characters to characters.[5]

See also

  • Sed
  • List of Unix commands
  • GNU Core Utilities

References

1. ^https://linux.die.net/man/1/tr
2. ^{{cite book|author=Paul S. Dayan|year=1992|title=The OS-9 Guru - 1 : The Facts|publisher=Galactic Industrial Limited|isbn=0-9519228-0-7}}
3. ^{{cite web|title=tr (String) - APIdock|url=http://apidock.com/ruby/String/tr|publisher=APIdock|accessdate=12 August 2015}}
4. ^{{cite web|title=tr - perldoc.perl.org|url=http://perldoc.perl.org/functions/tr.html|publisher=perldoc.perl.org|accessdate=12 August 2015}}
5. ^{{cite web|title=Tcl Built-In Commands - string manual page|url=https://www.tcl.tk/man/tcl8.4/TclCmd/string.htm#M33|accessdate=12 August 2015}}

External links

  • {{man|cu|tr|SUS}}
  • tr(1) – Unix 8th Edition manual page.
  • {{man|1|tr|FreeBSD}}
  • {{man|1|tr|Solaris}}
  • {{man|1|tr|Linux}}
  • usage examples at examplenow.com
{{Unix commands}}

2 : Unix text processing utilities|Unix SUS2008 utilities

随便看

 

开放百科全书收录14589846条英语、德语、日语等多语种百科知识,基本涵盖了大多数领域的百科知识,是一部内容自由、开放的电子版国际百科全书。

 

Copyright © 2023 OENC.NET All Rights Reserved
京ICP备2021023879号 更新时间:2024/11/10 17:11:18