1 .\" You may copy, distribute and modify under the terms of the LDP General
2 .\" Public License as specified in the LICENSE file that comes with the
3 .\" gnumaniak distribution
5 .\" The author kindly requests that no comments regarding the "better"
6 .\" suitability or up-to-date notices of any info documentation alternative
7 .\" is added without contacting him first.
9 .\" (C) 2002 Ragnar Hojland Espinosa <ragnar@ragnar-hojland.com>
12 .\" man pages are NOT obsolete!
13 .\" <ragnar@ragnar-hojland.com>
15 .\" Japanese Version Copyright (c) 2000 NAKANO Takeo all rights reserved.
16 .\" Translated Sun 12 Mar 2000 by NAKANO Takeo <nakano@apm.seikei.ac.jp>
18 .TH TR 1 "7 October 2002" "GNU textutils 2.1"
20 .\"O \fBtr\fR \- translate, squeeze, and/or delete characters
22 tr \- 文字の変換・削除や、連続する文字の圧縮を行う
27 .RB [ \-\-complement ]
29 .RB [ \-\-squeeze\-repeats ]
30 .RB [ \-\-truncate\-set1 ]
32 .\" .IR FILE1 " [" FILE2 ]
35 .BR tr " [" \-\-help "] [" \-\-version ]
39 .\"O copies standard input to standard output, performing one of the
40 .\"O following operations:
42 は標準入力を標準出力にコピーし、その際に以下のうちのいずれかを行う。
44 .\"O \fB\(bu\fR translate, and optionally squeeze repeated characters in the result
46 文字を変換し、オプションで指定すればさらに連続する文字を圧縮
49 .\"O \fB\(bu\fR squeeze repeated characters
53 .\"O \fB\(bu\fR delete characters
57 .\"O \fB\(bu\fR delete characters, then squeeze repeated characters from the result
59 文字を削除してから、連続する文字を圧縮する。
61 .\"O The \fISET1\fR and (if given) \fISET2\fR arguments define ordered sets of
62 .\"O characters, referred to below as \fISET1\fR and \fISET2\fR. These sets are
63 .\"O the characters of the input that \fBtr\fR operates on. The \fB\-c\fR option
64 .\"O replaces \fISET1\fR with its complement (all of the characters that are not
66 \fISET1\fP および (与えられていれば) \fISET2\fP 引き数は、
69 .\" 以下の説明ではこれを \fISET1\fP および \fISET2\fP と呼ぶ。
73 .\"nakano: 以下は冗長な気が...
75 .\" オプションは \fISET\fP をその補集合
76 .\" (\fISET1\fP に含まれない文字すべて) に置換する。
80 .B \-c, \-\-complement
81 .\"O Replace \fISET1\fR with its complement (that is, all the characters that are
82 .\"O not in \fISET1\fR.
83 \fISET1\fR を、 \fISET1\fR 自身の補集合
84 (\fISET1\fR に含まれない文字すべて) で置き換える。
87 .\"O Delete any input characters that are in \fISET1\fR, do not translate.
88 \fISET1\fP にある入力文字を削除する。変換しない。
90 .B \-s, \-\-squeeze\-repeats
91 .\"O Replace sequence of characters with one; this is done after translating or
92 .\"O deleting. It replaces each input sequence of a repated character that is in
93 .\"O \fISET1\fR with a single occurrence of that character.
94 同じ文字の繰り返しを 1 文字に置き換える。
96 \fISET1\fP にある文字の繰り返しを、その文字 1 文字に置き換える。
98 .B \-t, \-\-truncate\-set1
99 .\"O Before doing any translations, first truncate \fISET1\fR to length of
101 変換を行う前に、まず \fISET1\fP を \fISET2\fP の長さに切り詰める。
104 .\"O Print a usage message on standard output and exit successfully.
105 標準出力に使用方法のメッセージを出力して正常終了する。
108 .\"O Print version information on standard output then exit successfully.
109 標準出力にバージョン情報を出力して正常終了する。
110 .\"O .SH SPECIFYING SETS
112 .\"O The format of the \fISET1\fR and \fISET2\fR arguments resembles the format of
113 .\"O regular expressions; however, they are not regular expressions, only
114 .\"O lists of characters. Most characters simply represent themselves in
115 .\"O these strings, but the strings can contain the shorthands listed below,
116 .\"O for convenience. Some of them can be used only in \fISET1\fR or \fISET2\fR,
118 \fISET1\fP および \fISET2\fP 引き数のフォーマットは
119 正規表現と似たものになっている。しかし正規表現そのものではなく、
121 これらの文字列の中に記された文字は、ほとんどの場合はその文字自身を指す。
122 文字列には便宜上以下のような短縮形を用いることもできる。
123 ただし \fISET1\fP または \fISET2\fP のいずれかにしか
124 用いることのできないものもある (このようなものには注記がされている)。
125 .\"O .SS Backslash Escapes
126 .SS バックスラッシュを用いたエスケープ
151 .\"O The character with the value given by \fIOOO\fR, which is 1 to 3 octal digits
152 \fIOOO\fP (1〜3 桁の 8 進数) によって指定される文字
160 .\"O The notation `\fIM\fR\-\fIN\fR' expands to all of the characters from
161 .\"O \fiM\fR through \fIN\fR, in ascending order. \fIM\fR should collate before
162 .\"O \fIN\fR; if it doesn't, an error results. As an example, `0\-9' is the same as
163 .\"O `0123456789'. Although GNU \fBtr\fR does not support the System V
164 .\"O syntax that uses square brackets to enclose ranges, translations
165 .\"O specified in that format will still work as long as the brackets
166 .\"O in \fISTRING1\fR correspond to identical brackets in \fISTRING2\fR.
167 `\fIM\fR\-\fIN\fR' といった表記は、
168 \fIM\fP から \fIN\fP までのすべての文字を昇順に展開した文字列になる。
169 \fIM\fP は照合順序中で \fIN\fP の前になければならず、
171 例えば `0\-9' は`0123456789' を指定したのと同じことになる。
174 では範囲を指定する際に角括弧 `[]' を用いるが、
179 \fISET1\fP と \fISET2\fP の間で角括弧が対応していればちゃんと動作する。
180 .\"O .SS Repeated Characters
182 .\"O The notation `\fB[\fIC\fB*\fIN\fB]\fR' in \fISET2\fR expands to \fIN\fR
183 .\"O copies of character \fIC\fR. Thus, `[y*6]' is the same as `yyyyyy'. The
184 .\"O notation `[C*]' in \fISTRING2\fR expands to as many copies of C as are
185 .\"O needed to make \fISET2\fR as long as \fISET1\fR. If \fIN\fR begins with
186 .\"O `0', it is interpreted in octal, otherwise in decimal.
187 \fISET2\fP における `\fB[\fIC\fP*\fIN\fB]\fR' といった表記は
188 \fIN\fP 個の文字 \fIC\fP に展開される。
189 したがって `[y*6]' は `yyyyyy' になる。
190 \fISET2\fP における `[\fIC\fP*]' は \fISET2\fP を \fISET1\fP
191 と同じ長さにするために必要な個数の文字 \fIC\fP に展開される。
192 \fIN\fP が 0 ではじまる場合は 8 進数とみなされ、
193 それ以外の場合は 10 進数とみなされる。
194 .\"O .SS Character Classes
196 .\"O The notation `\fB[:\fICLASS\fB:]\fR' expands to all of the
197 .\"O characters in the
198 .\"O (predefined) class \fICLASS\fR. The characters expand in no particular
199 .\"O order, except for the \fBupper\fR and \fBlower\fR classes, which expand in
200 .\"O ascending order. When the \fB\-\-delete\fR and \fB\-\-squeeze\-repeats\fR
201 .\"O options are both given, any character class can be used in \fISET2\fR.
202 .\"O Otherwise, only the character classes \fBlower\fR and \fBupper\fR are
203 .\"O accepted in \fISET2\fR, and then only if the corresponding character class
204 .\"O (\fBupper\fR and \fBlower\fR, respectively) is specified in the same
205 .\"O relative position in \fISET1\fR. Doing this specifies case conversion. The
206 .\"O class names are given below; an error results when an invalid class name is
208 `\fB[:\fICLASS\fB:]\fR' といった表記は、
209 あらかじめ定義された文字クラス \fICLASS\fP のすべての文字に展開される。
210 文字クラスには特定の順序は定義されていない。
211 ただし `upper' と `lower' クラスのみは例外で、昇順に展開される。
212 .BR \-\-delete " (" \-d )
214 .BR \-\-squeeze\-repeats " (" \-s )
216 \fISET2\fP にはどんな文字クラスでも用いることができる。
217 それ以外の場合は、 \fISET2\fP に指定できるのは `lower' および `upper' のみで、
219 (`lower' には `upper'、 `upper' には `lower') が
220 \fISET1\fP の同じ位置に指定されていなければならない。
223 これら以外の名前が指定された場合にはエラーとなる。
227 .\"O Letters and digits
235 .\"O Horizontal whitespace
236 水平方向の空白 (Horizontal whitespace)
239 .\"O Control characters
247 .\"O Printable characters, not including space
251 .\"O Lowercase letters
255 .\"O Printable characters, including space
259 .\"O Punctuation characters
263 .\"O Horizontal or vertical whitespace
267 .\"O Uppercase letters
271 .\"O Hexadecimal digits
274 .\"O .SS Equivalence Classes
276 .\"O The syntax `\fB[=\fIC\fB=]\fR' expands to all of the characters that are
277 .\"O equivalent to \fIC\fR, in no particular order. Equivalence classes are
278 .\"O a relatively recent invention intended to support non-English alphabets.
279 .\"O But there seems to be no standard way to define them or determine their
280 .\"O contents. Therefore, they are not fully implemented in GNU \fBtr\fR; each
281 .\"O character's equivalence class consists only of that character, which is of
282 .\"O no particular use.
283 `\fB[=\fIC\fB=]\fR' といった表記は、
284 \fIC\fP と等価な文字に展開される。このとき順序は定義されない。
285 等価クラスは、英語以外のアルファベットをサポートするために
287 しかし現在のところこれらの定義や内容指定に標準的な方法はないようである。
291 それぞれの文字の等価クラスはその文字からのみ構成されている。
292 したがってこの機能は現在のところ役に立たない。
295 .\"O \fBtr\fR performs translation when \fISET1\fR and \fISET2\fR are both given and
296 .\"O \fB\-\-delete\fR is not specified. \fRtr\fN translates each character
297 .\"O of its input that is in \fISET1\fR to the corresponding character in \fISET2\fR.
298 .\"O Characters not in \fISET1\fR are passed through unchanged. When a character
299 .\"O appears more than once in \fISET1\fR and the corresponding characters in \fISET2\fR
300 .\"O are not all the same, only the final one is used. For example, these
301 .\"O two commands are equivalent:
303 は \fISET1\fP と \fISET2\fP の両方が指定されていて、
304 .BR \-\-delete " (" \-d )
305 オプションが指定されていない場合には変換を行う。
307 は入力のうち \fISET1\fR にある文字を
308 \fISET2\fR の対応する位置にある文字に変換する。
309 \fISET1\fR に無い文字はそのまま出力される。
310 もし文字が \fISET1\fR に 2 回以上現われ、
311 \fISET2\fR の対応する文字がすべて同じでない場合には、
312 最後の文字だけが使われる。例えば以下の二つのコマンドは等価である:
321 .\"O A common use of \fBtr\fR is to convert lowercase characters to
322 .\"O uppercase. This can be done in many ways. Here are three of them:
324 の良くある使い方としては、英小文字の大文字への変換があげられる。
325 いろいろなやり方が可能であるが、以下に例を 3 つ示す。
329 tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ
331 tr '[:lower:]' '[:upper:]'
335 .\"O When \fBtr\fR is performing translation, \fISET1\fR and \fISET2\fR typically have
336 .\"O the same length. If \fISET1\fR is shorter than \fISET2\fR, the extra characters at
337 .\"O the end of \fISET2\fR are ignored.
339 が変換を行う際には、 \fISET1\fR と \fISET2\fR は通常同じ長さでなければならない。
340 \fISET1\fR が \fISET2\fR より短い場合には、 \fISET2\fR の尾部の余りは無視される。
342 .\"O On the other hand, making \fISET1\fR longer than \fISET2\fR is not portable;
343 .\"O POSIX.2 says that the result is undefined. In this situation, BSD \fBtr\fR
344 .\"O pads \fISET2\fR to the length of \fISET1\fR by repeating the last character
345 .\"O of \fISET2\fR as many times as necessary. System V \fBtr\fR truncates
346 .\"O \fBSET1\fR to the length of \fBSET2\fR.
347 逆に \fISET1\fR を \fISET2\fR より長く指定すると、動作は予測できなくなる。
348 POSIX.2 によれば、結果は定義されない。
351 では \fISET2\fR の足りない部分を最後の文字で埋め、 \fISET1\fR と同じ長さにする。
354 は \fISET1\fR の尾部を切り捨てて \fISET2\fR と同じ長さにする。
356 .\"O By default, GNU \fBtr\fR handles this case like BSD \fBtr\fR. When the
357 .\"O \fB\-\-truncate\-set1\fR option is given, GNU \fBtr\fR handles this case
358 .\"O like the System V \fBtr\fR instead. This option is ignored for operations
359 .\"O other than translation. Acting like System V \fBtr\fR in this case breaks the
360 .\"O relatively common BSD idiom:
366 また \-\-truncate\-set1 (\fI\-t\fP) オプションが指定された場合には、
371 のように振る舞う。このオプションは変換以外の点に関しては無視される。
374 的な振る舞いの下では、 BSD 版の有名な用法:
378 tr \-cs A\-Za\-z0\-9 '\e012'
382 .\"O because it converts only zero bytes (the first element in the
383 .\"O complement of \fISET1\fR), rather than all non-alphanumerics, to newlines.
384 は使えなくなる。これはアルファベット文字および数字以外の文字を改行文字
385 に置換するものであるが、 System V では内容が 0 のバイト
386 (\fISET1\fR の補集合の先頭要素) のみを変換することになる。
387 .\"O .SH SQUEEZING REPEATS AND DELETING
389 .\"O When given just the \fB\-\-delete\fR option, \fBtr\fR removes any input
390 .\"O characters that are in \fISET1\fR.
391 .BR \-\-delete " (" \-d )
394 は入力のうち \fISET1\fR にある文字を削除する。
396 .\"O When given just the \fB\-\-squeeze\-repeats\fR option, \fBtr\fR replaces
397 .\"O each input sequence of a repeated character that is in \fISET1\fR with a
398 .\"O single occurrence of that character.
399 .BR \-\-squeeze\-repeats " (" \-s )
402 は入力のうち、 \fISET1\fR にある文字の繰り返しを、その文字 1 文字に置き換える。
404 .\"O When given both \fB\-\-delete\fR and \fB\-\-squeeze\-repeats\fR, \fBtr\fR
405 .\"O first performs any deletions using \fISET1\fR, then squeezes repeats from any
406 .\"O remaining characters using \fISET2\fR.
407 .BR \-\-delete " と " \-\-squeeze\-repeats
410 はまず \fISET1\fR にある文字を削除し、
411 残りのうち \fISET2\fR にある文字の繰り返しを圧縮する。
413 .\"O The \fB\-\-squeeze\-repeats\fR option may also be used when translating, in
414 .\"O which case tr' first performs translation, then squeezes repeats from
415 .\"O any remaining characters using \fISET2\fR.
416 .B \-\-squeeze\-repeats
417 オプションは変換と共に用いることもできる。この場合には
419 はまず変換を行い、残りの文字のうち \fISET2\fR にあるものを圧縮する。
421 .\"O Here are some examples to illustrate various combinations of options:
422 以下にこれらのオプションを組み合わせた利用例を示す:
424 .\"O \fB\(bu\fR Remove all zero bytes
425 \fB\(bu\fR 内容が 0 のバイトを削除する:
433 .\"O \fB\(bu\fR Put all words on lines by themselves. This converts all
434 .\"O non-alphanumeric characters to newlines, then squeezes each string
435 .\"O of repeated newlines into a single newline
436 \fB\(bu\fR すべての単語をそれ自身のみからなる行に変換する。
437 つまりアルファベット文字、数字以外の文字を改行文字に変換し、
438 改行文字の繰り返しを一つの改行文字に圧縮する:
442 tr \-cs '[a\-zA\-Z0\-9]' '[\en*]'
446 .\"O \fB\(bu\fR Convert each sequence of repeated newlines to a single newline
447 \fB\(bu\fR 改行文字の繰り返しを一つの改行文字に変換する。
455 .\"O \fB\(bu\fR Find doubled occurrences of words in a document. For example,
456 .\"O people often write "the the" with the duplicated words separated by a
457 .\"O newline. The bourne shell script below works first by converting each
458 .\"O sequence of punctuation and blank characters to a single newline. That puts
459 .\"O each "word" on a line by itself. Next it maps all uppercase characters to
460 .\"O lower case, and finally it runs \fBuniq\fR(1) with the \fB\-d\fR option to
461 .\"O print out only the words that were adjacent duplicates.
462 \fB\(bu\fR 文書中の同じ単語の連続を見つける。例えば
463 "the the" のように、改行を挟んで単語をダブって書いてしまうことがよくある。
464 以下の bourne シェルスクリプトは、まず句読点や空白の連続を改行に変換する。
465 これによって、各「単語」は、それぞれ自分自身だけからなる行に置かれる。
470 オプションで起動して、連続した同じ単語だけを表示する。
476 | tr \-s '[:punct:][:blank:]' '\en' \e
477 | tr '[:upper:]' '[:lower:]' \e
482 .\"O .SH COMPATIBILITY
484 .\"O Setting the environment variable \fBPOSIXLY_CORRECT\fR turns off the
485 .\"O following warning and error messages, for strict compliance with
486 .\"O POSIX.2. Otherwise, the following diagnostics are issued:
489 を指定すると、 POSIX.2 との厳密な互換性をとるために、
490 警告およびエラーメッセージのいくつかが出力されなくなる。
491 指定しなければ、以下のような場合にメッセージが出る。
493 .\"O 1. When the \fB\-\-delete\fR option is given but \fB\-\-squeeze\-repeats\fR is
494 .\"O not, and \fISET2\fR is given, GNU \fBtr\fR by default prints a usage message
495 .\"O and exits, because \fISET2\fR would not be used. The POSIX specification
496 .\"O says that \fISET2\fR must be ignored in this case. Silently ignoring
497 .\"O arguments is a bad idea.
501 .B \-\-squeeze\-repeats
502 が指定されておらず、かつ \fISET2\fP が与えられている場合には、GNU 版
504 はデフォルトでは使用法のメッセージを表示して終了する。
505 なぜならこのとき \fISET2\fP は利用されないからである。
507 この場合は \fISET2\fP は単に無視されなければならない。
508 引き数を黙って無視するのは良くない仕様だと思うのだが。
510 .\"O 2. When an ambiguous octal escape is given. For example, `\400' is
511 .\"O actually \40' followed by the digit `0', because the value 400
512 .\"O octal does not fit into a single byte.
514 あいまいな 8 進数エスケープが指定された場合。例えば `\e400' は実際に
515 は \e40 と数字 0 の並びと解釈される。
516 なぜなら 8 進数の 400 に対応するバイトは存在しないからである。
518 .\"O GNU \fBtr\fR does not provide complete BSD or System V compatibility.
519 .\"O For example, it is impossible to disable interpretation of the POSIX
520 .\"O constructs `[:alpha:]', `[=c=]', and `[c*10]'. Also, GNU \fBtr\fR does not
521 .\"O delete zero bytes automatically, unlike traditional Unix versions,
522 .\"O which provide no way to preserve zero bytes.
525 は BSD や System V と互換ではない。
526 例を挙げれば、 POSIX 定義にある `[:alpha:]', `[=c=]', `[c*10]'
527 といった指定の解釈を止めさせるようなオプションは存在しない。
530 は内容が 0 のバイトを自動的には削除しない。
531 一方これまでの UNIX 版では、このバイトを残す方法の方が存在しない。
534 .\"O Report bugs to bug-textutils@gnu.org.
536 .\"O Man page by Ragnar Hojland Espinosa <ragnar@ragnar-hojland.com>
537 プログラムのバグについては bug-textutils@gnu.org に報告してください。
539 man ページは Ragnar Hojland Espinosa <ragnar@ragnar-hojland.com> が作成しました。