212 lines
5.1 KiB
HTML
212 lines
5.1 KiB
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
|
|
<html>
|
|
<head>
|
|
<meta name="generator" content="HTML Tidy, see www.w3.org">
|
|
<meta http-equiv="Content-Type" content=
|
|
"text/html; charset=utf-8">
|
|
<title>tr - Translate characters</title>
|
|
<LINK rel="stylesheet" type="text/css" href="../rzahg/ic.css">
|
|
</HEAD>
|
|
<body bgcolor="#FFFFFF">
|
|
<!-- Java sync-link -->
|
|
<SCRIPT LANGUAGE="Javascript" SRC="../rzahg/synch.js" TYPE="text/javascript"></SCRIPT>
|
|
|
|
|
|
|
|
<h2>tr - Translate
|
|
characters</h2>
|
|
|
|
<p><strong>Synopsis</strong></p>
|
|
|
|
<p><strong>tr [-cs]</strong> <em>string1 string2</em></p>
|
|
|
|
<p><strong>tr [-c] -d</strong> <em>string1</em></p>
|
|
|
|
<p><strong>tr [-c] -s</strong> <em>string1</em></p>
|
|
|
|
<p><strong>tr [-c] -ds</strong> <em>string1 string2</em></p>
|
|
|
|
<p><strong>Description</strong></p>
|
|
|
|
<p>The <strong>tr</strong> utility copies the standard input to the
|
|
standard output with substitution or deletion of selected
|
|
characters.</p>
|
|
|
|
<p>In the first synopsis form, the characters in <em>string1</em>
|
|
are translated into the characters in <em>string2</em> where the
|
|
first character in <em>string1</em> is translated into the first
|
|
character in <em>string2</em> and so on. If <em>string1</em> is
|
|
longer than <em>string2</em>, the last character found in <em>
|
|
string2</em> is duplicated until <em>string1</em> is exhausted.</p>
|
|
|
|
<p>In the second synopsis form, the characters in <em>string1</em>
|
|
are deleted from the input.</p>
|
|
|
|
<p>In the third synopsis form, the characters in <em>string1</em>
|
|
are compressed as described for the <strong>-s</strong> option
|
|
below.</p>
|
|
|
|
<p>In the fourth synopsis form, the characters in <em>string1</em>
|
|
are deleted from the input, and the characters in <em>string2</em>
|
|
are compressed as described for the <strong>-s</strong> option
|
|
below.</p>
|
|
|
|
<p>The following conventions can be used in <em>string1</em> and
|
|
<em>string2</em> to specify sets of characters. Any character not
|
|
described by one of the following conventions represents
|
|
itself.</p>
|
|
|
|
<dl>
|
|
<dt><strong>nnn</strong></dt>
|
|
|
|
<dd>A backslash (\) followed by 1, 2 or 3 octal digits represents a
|
|
character with that encoded value.</dd>
|
|
|
|
<dt><strong>char</strong></dt>
|
|
|
|
<dd>To follow an octal sequence with a digit as a character, left
|
|
zero-pad the octal sequence to the full 3 octal digits. A backslash
|
|
(\) followed by certain special characters maps to special values.
|
|
The special characters and their values are:
|
|
|
|
<ul>
|
|
<li>a - alert character</li>
|
|
|
|
<li>b - backspace</li>
|
|
|
|
<li>f - form-feed</li>
|
|
|
|
<li>n - newline</li>
|
|
|
|
<li>r - carriage return</li>
|
|
|
|
<li>t - tab</li>
|
|
|
|
<li>v - vertical tab</li>
|
|
|
|
<li>A backslash (\) followed by any other character maps to that
|
|
character.</li>
|
|
</ul>
|
|
</dd>
|
|
|
|
<dt><strong>c-c</strong></dt>
|
|
|
|
<dd>Represents the range of characters between the range endpoints,
|
|
inclusively.</dd>
|
|
|
|
<dt><strong>[:class:]</strong></dt>
|
|
|
|
<dd>Represents all characters belonging to the defined character
|
|
class. These are the class names:
|
|
|
|
<ul>
|
|
<li>alnum - alphanumeric characters</li>
|
|
|
|
<li>alpha - alphabetic characters</li>
|
|
|
|
<li>cntrl - control characters</li>
|
|
|
|
<li>digit - numeric characters</li>
|
|
|
|
<li>graph - graphic characters</li>
|
|
|
|
<li>lower - lower-case alphabetic characters</li>
|
|
|
|
<li>print - printable characters</li>
|
|
|
|
<li>punct - punctuation characters</li>
|
|
|
|
<li>space - space characters</li>
|
|
|
|
<li>upper - upper-case characters</li>
|
|
|
|
<li>xdigit - hexadecimal characters</li>
|
|
</ul>
|
|
|
|
<table>
|
|
<tr>
|
|
<td valign="top"><strong>Note:</strong></td>
|
|
<td>With the exception of the upper and lower classes, characters
|
|
in the classes are in unspecified order. In the upper and lower
|
|
classes, characters are entered in ascending order.</td>
|
|
</tr>
|
|
</table>
|
|
</dd>
|
|
</dl>
|
|
|
|
<p><strong>Options</strong></p>
|
|
|
|
<dl>
|
|
<dt><strong>-c</strong></dt>
|
|
|
|
<dd>Complement the set of characters in <em>string1</em>, that is
|
|
<strong>-c ab</strong> includes every character except for "a" and
|
|
"b".</dd>
|
|
|
|
<dt><strong>-d</strong></dt>
|
|
|
|
<dd>Delete characters from the input.</dd>
|
|
|
|
<dt><strong>-s</strong></dt>
|
|
|
|
<dd>Squeeze multiple occurrences of the characters listed in the
|
|
last operand (either <em>string1</em> or <em>string2</em>) in the
|
|
input into a single instance of the character. This occurs after
|
|
all deletion and translation is completed.</dd>
|
|
</dl>
|
|
|
|
<p><strong>Exit Status</strong></p>
|
|
|
|
<ul>
|
|
<li>0 on success</li>
|
|
|
|
<li>>0 if an error occurs.</li>
|
|
</ul>
|
|
|
|
<p><strong>Related information</strong></p>
|
|
|
|
<ul>
|
|
<li><a href="cut.htm">cut - Cut out selected fields of each line of
|
|
a file</a></li>
|
|
|
|
<li><a href="grep.htm">grep - Search a file for a pattern</a></li>
|
|
|
|
<li><a href="tr.htm">tr - translate characters</a></li>
|
|
|
|
<li><a href="wc.htm">wc - Word, line and byte/character
|
|
count</a></li>
|
|
</ul>
|
|
|
|
<p><strong>Examples</strong></p>
|
|
|
|
<ol>
|
|
<li>Create a list of the words in file1, one per line, where a word
|
|
is taken to be a maximal string of letters.
|
|
|
|
<pre>
|
|
tr -cs '[:alpha:]' 'n' < file1
|
|
</pre>
|
|
</li>
|
|
|
|
<li>Translate the contents of file1 to upper-case.
|
|
|
|
<pre>
|
|
tr '[:lower:]' '[:upper:]' < file1
|
|
tr 'a-z' 'A-Z' < file1
|
|
</pre>
|
|
</li>
|
|
|
|
<li>Remove the non-printable characters from file1.
|
|
|
|
<pre>
|
|
tr -cd '[:print:]' < file1
|
|
</pre>
|
|
</li>
|
|
</ol>
|
|
|
|
|
|
<!-- end ibmbody========================================================= -->
|
|
</body>
|
|
</html>
|
|
|