Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Tr (Unix)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{short description|Unix text formatting utility}} {{lowercase title}} {{Infobox software | name = tr | logo = | screenshot = Tr Unix.png | screenshot size = | caption = The {{code|tr}} command | author = [[Douglas McIlroy]]<br />([[AT&T Bell Laboratories]]) | developer = Various [[open-source software|open-source]] and [[commercial software|commercial]] developers | released = {{Start date and age|1973|11}} | latest release version = | latest release date = | programming language = [[C (programming language)|C]] | operating system = [[Unix]], [[Unix-like]], [[Plan 9 from Bell Labs|Plan 9]], [[Inferno (operating system)|Inferno]], [[OS-9]], [[MSX-DOS]], [[IBM i]] | platform = [[Cross-platform]] | genre = [[Command (computing)|Command]] | license = [[coreutils]]: [[GPLv3+]]<br />Plan 9: [[MIT License]] | website = }} '''tr''' is a [[command (computing)|command]] in [[Unix]], [[Plan 9 from Bell Labs|Plan 9]], [[Inferno (operating system)|Inferno]], 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 [[Command-line argument|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, tr 'abcd' 'jkmn' 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: tr 'a-d' 'jkmn' In [[POSIX]]-compliant versions of <code>tr</code>, the set represented by a character range depends on the [[Locale (computer software)|locale's]] [[Collation|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 ''<code>s</code>'' flag causes <code>tr</code> to compress sequences of identical adjacent characters in its output to a single token. For example, tr -s '\n' replaces sequences of one or more newline characters with a single newline. The ''<code>d</code>'' flag causes <code>tr</code> 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. tr -d '\r' The ''<code>c</code>'' flag indicates the complement of the first set of characters. The invocation tr -cd '[:alnum:]' therefore removes all non-alphanumeric characters. ==Implementations== The original version of <code>tr</code> was written by [[Douglas McIlroy]] and was introduced in [[Research Unix|Version 4 Unix]].<ref name="reader">{{cite tech report |first1=M. D. |last1=McIlroy |author-link1=Doug McIlroy |year=1987 |url=http://www.cs.dartmouth.edu/~doug/reader.pdf |title=A Research Unix reader: annotated excerpts from the Programmer's Manual, 1971β1986 |series=Computing Science |number=139 |institution=AT&T Bell Laboratories |df=dmy-all }}</ref> The version of <code>tr</code> bundled in [[GNU]] [[coreutils]] was written by Jim Meyering.<ref>{{Cite web|url=https://linux.die.net/man/1/tr|title=Tr(1): Translate/Delete char - Linux man page}}</ref> The command is available as a separate package for [[Microsoft Windows]] as part of the [[UnxUtils]] collection of [[Native (computing)|native]] [[Windows API|Win32]] [[porting|ports]] of common GNU Unix-like utilities.<ref>{{Cite web|url=http://unxutils.sourceforge.net/|title=Native Win32 ports of some GNU utilities|website=unxutils.sourceforge.net}}</ref> It is also available in the [[OS-9]] shell.<ref>{{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}}</ref> A <code>tr</code> command is also part of [[ASCII Corporation|ASCII]]'s ''MSX-DOS2 Tools'' for [[MSX-DOS]] version 2.<ref>[https://archive.org/details/MSXDOS2TOOLS MSX-DOS2 Tools User's Manual by ASCII Corporation]</ref> The {{Mono|tr}} command has also been ported to the [[IBM i]] operating system.<ref>{{cite web |title=IBM System i Version 7.2 Programming Qshell |language=en |author=IBM |website=[[IBM]] |author-link=IBM |url=https://www.ibm.com/support/knowledgecenter/ssw_ibm_i_74/rzahz/rzahzpdf.pdf?view=kc |access-date=2020-09-05 }}</ref> Most versions of <code>tr</code>, including GNU <code>tr</code> and classic Unix <code>tr</code>, operate on single-byte characters and are not [[Unicode]] compliant. An exception is the [[Heirloom Project|Heirloom Toolchest]] implementation, which provides basic Unicode support. [[Ruby (programming language)|Ruby]] and [[Perl]] also have an internal ''tr'' operator, which operates analogously.<ref>{{cite web|title=tr (String) - APIdock|url=https://apidock.com/ruby/String/tr|publisher=APIdock|access-date=12 August 2015}}</ref><ref name=Perl_trDoc>{{cite web|title=tr - perldoc.perl.org|url=https://perldoc.perl.org/functions/tr.html|publisher=perldoc.perl.org|access-date=12 August 2015}}</ref> [[Tcl]]'s ''string map'' command is more general in that it maps strings to strings while tr maps characters to characters.<ref name=TCLManualPage>{{cite web|title=Tcl Built-In Commands - string manual page|url=https://www.tcl.tk/man/tcl8.4/TclCmd/string.htm#M33|access-date=12 August 2015}}</ref> ==See also== * [[sed]] * [[List of Unix commands]] * [[GNU Core Utilities]] ==References== {{Reflist}} ==External links== {{Wikibooks|Guide to Unix|Commands}} * {{man|cu|tr|SUS}} * [http://man.cat-v.org/unix_8th/1/tr tr(1)] β Unix 8th Edition manual page. * {{man|1|tr|FreeBSD}} * {{man|1|tr|Solaris}} * {{man|1|tr|Linux}} * {{man|1|tr|Plan 9}} * {{man|1|tr|Inferno}} * [https://web.archive.org/web/20120723113341/http://www.examplenow.com/tr/ usage examples at examplenow.com] {{Unix commands}} {{Plan 9 commands}} {{Core Utilities commands}} [[Category:Unix text processing utilities]] [[Category:Unix SUS2008 utilities]] [[Category:Plan 9 commands]] [[Category:Inferno (operating system) commands]] [[Category:IBM i Qshell commands]]
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)
Pages transcluded onto the current version of this page
(
help
)
:
Template:Cite book
(
edit
)
Template:Cite tech report
(
edit
)
Template:Cite web
(
edit
)
Template:Core Utilities commands
(
edit
)
Template:Infobox
(
edit
)
Template:Infobox software
(
edit
)
Template:Lowercase title
(
edit
)
Template:Main other
(
edit
)
Template:Man
(
edit
)
Template:Mono
(
edit
)
Template:Plan 9 commands
(
edit
)
Template:Reflist
(
edit
)
Template:Short description
(
edit
)
Template:Sister project
(
edit
)
Template:Template other
(
edit
)
Template:Unix commands
(
edit
)
Template:Wikibooks
(
edit
)