-
Notifications
You must be signed in to change notification settings - Fork 1
/
cut.1
104 lines (72 loc) · 3.49 KB
/
cut.1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
CUT(1) Human68k ITA TOOLBOX User's Manual CUT(1)
名称
cut - ファイルの各行から指定フィールドを切り出す
形式
cut -b list [ -nBCZ ] [ -- ] [ file ] ...
cut -c list [ -BCZ ] [ -- ] [ file ] ...
cut -f list [ -d char ] [ -sBCZ ] [ -- ] [ file ] ...
解説
cut は各 file を順次読み取り,各行から指定されたフィールドと
改行(^J または ^M^J)を取り出して標準出力に出力します.
file が 1つも指定されていない場合,または file が‘-’である
場合には標準入力から読み取りを行います.file がオープンでき
ないときにはエラー・メッセージを標準エラー出力に出力して処理
を継続します.
オプション -b,-c,-f のうち 1つを必ず使用しなければなりませ
ん.-b,-c,-f に対するオプション引数 list は,切り出すフィー
ルド番号を並べたリストです.たとえば‘5’は 5番目のフィール
ド,‘-5’は 1番目から 5番目までのフィールド範囲,‘2-5’は
2番目から 5番目までのフィールド範囲,‘5-’は 5番目以降のす
べてのフィールド範囲を表します.複数のフィールド範囲を‘,’
で連結して指定することができます.たとえば‘2,5-7,10’は 2,
5,6,7,10番目のフィールドを表します.
-b ではフィールドはバイト単位です.通常はマルチバイト文字に
ついて配慮しませんが,-n オプションを指定すると,シフトJIS
2バイト文字の断片はブランクに替えて出力します.
-c ではフィールドは文字単位です.シフトJIS 2バイト文字も 1文
字として扱われます.
-f では行を文字 char で区切ったフィールド単位での切り出しを
行います.出力されるフィールドとフィールドとの間には char が
狭まれます.char を含まない行は,通常はそのまま出力されます
が,-s オプションを指定すると除去されます.char にはシフト
JIS 2バイト文字を含む任意の 1文字を指定することができます.
-d オプションが指定されていない場合の char のデフォルトは水
平タブです.
その他のオプションを以下に示します.
-B 決して ^J コードの ^M^J への変換を行いません.通常は,
出力が cooked モードのキャラクタ・デバイス(CON や PRN
など)である場合には,^M に続いていない ^J コードを
^M^J に変換して出力します.
-C -B オプションと逆に,^M に続いていない ^J コードを常に
^M^J に変換して出力します.
-Z いかなる入力からも,^Z (control-Z) コードを EOF と見な
して入力を打ち切ります.通常は,入力が cooked モードの
キャラクタ・デバイス(CON など)である場合にのみ,^D か
または ^Z を読み取ると,それを EOF コードと見なして入力
を打ち切ります.
例
次の例は /etc/passwd ファイルからログイン名と実名のリストを
作成してファイル users に書き出します.
cut -f1,5 -d\; /etc/passwd > users
この例では fish(1) などのシェルから実行することを想定して,
フィールドの区切り文字として指定する‘;’をシェルから保護す
るために‘\’でエスケープしています.
関連事項
paste(1)
診断
何らかのエラーがあったときにはエラー・メッセージが標準エラー
出力に出力されます.
終了ステータスとしては,引数の記述に間違いがあった場合には 1,
ファイルがオープンできなかったり入力に失敗した場合には 2,出
力エラーやメモリ不足など,システムの問題により正常に実行でき
なかった場合には 3,すべてが正常に終了したならば 0 が返りま
す.^C などによって中断したときの終了ステータスは OS の仕様
によります.
制限
-f オプション使用時には,入力行の長さは改行を含めて1024バイ
ト以内でなければなりません.
バージョン
1.1
制作・著作
Copyright(C)1994-95 by 板垣 史彦 (Itagaki Fumihiko)
1.1 Last change: 01 Jun 1995 Itagaki Fumihiko