Unix-commands-csplit
提供:Dev Guides
csplit-Unix、Linuxコマンド
NAME
*csplit* -ファイルをコンテキスト決定された断片に分割します。
概要
csplit [options]... FILE PATTERN...
説明
cspiltは、PATTERNで区切られたFILEの断片をファイル「xx00」、「xx01」、…に出力し、各断片のバイトカウントを標準出力に出力します。 (FILEが-の場合の標準入力)。
オプション
Tag | Description |
---|---|
-f PREFIX—prefix=PREFIX | Use PREFIX as the output file name prefix. |
-b SUFFIX—suffix=SUFFIX | Use SUFFIX as the output file name suffix. When this option is specified, the suffix string must include exactly one 'printf(3)'-style conversion specification, possibly including format specification flags, a field width, a precision specifications, or all of these kinds of modifiers. The format letter must convert a binary integer argument to readable form; thus, only 'd', 'i', 'u', 'o', 'x', and 'X' conversions are allowed. The entire SUFFIX is given (with the current output file number) to 'sprintf(3)' to form the file name suffixes for each of the individual output files in turn. If this option is used, the '--digits' option is ignored. |
-n DIGITS—digits=DIGITS | Use output file names containing numbers that are DIGITS digits long instead of the default 2. |
-k—keep-files | Do not remove output files when errors are encountered. |
-z—elide-empty-files | Suppress the generation of zero-length output files. (In cases where the section delimiters of the input file are supposed to mark the first lines of each of the sections, the first output file will generally be a zero-length file unless you use this option.) The output file sequence numbers always run consecutively starting from 0, even when this option is specified. |
-s-q—silent—quiet | Do not print counts of output file sizes. |
パターン
以下に詳述するように、出力ファイルの内容はPATTERN引数によって決定されます。 PATTERN引数が入力ファイルの存在しない行を参照している場合(たとえば、指定された正規表現に一致する残りの行がない場合)、エラーが発生します。 すべてのパターンが一致すると、残りの入力は最後の1つの出力ファイルにコピーされます。 デフォルトでは、「csplit」は各出力ファイルが作成された後に書き込まれたバイト数を出力します。 出力ファイルの名前は、接頭辞(デフォルトでは「xx」)とそれに続く接尾辞で構成されます。 デフォルトでは、接尾辞は「00」から「99」までの2桁の10進数の昇順です。 いずれの場合でも、出力ファイルをファイル名でソートされた順序で連結すると、元の入力ファイルが生成されます。 デフォルトでは、「csplit」がエラーを検出するか、ハングアップ、割り込み、終了、または終了信号を受信すると、終了する前に作成した出力ファイルをすべて削除します。
Tag | Description |
---|---|
N | Create an output file containing the input up to but not including line N (a positive integer). If followed by a repeat count, also create an output file containing the next LINE lines of the input file once for each repeat. |
/REGEXP/[OFFSET] | Create an output file containing the current line up to (but not including) the next line of the input file that contains a match for REGEXP. The optional OFFSET is a '+' or '-' followed by a positive integer. If it is given, the input up to the matching line plus or minus OFFSET is put into the output file, and the line after that begins the next section of input. |
%REGEXP%[OFFSET] | Like the previous type, except that it does not create an output file, so that section of the input file is effectively ignored. |
{REPEAT-COUNT} | Repeat the previous pattern REPEAT-COUNT additional times. REPEAT-COUNT can either be a positive integer or an asterisk, meaning repeat as many times as necessary until the input is exhausted. |
例
サンプルファイルsample.txtを用意しましょう
$ cat sample.txt
Line 1
Line 2
Line 3
Line 4
Line 5
Line 6
Line 7
Line 8
Line 9
Line 10
ファイルをこぼし、分割されたファイルを確認します。
$ csplit sample.txt 5 28 43
$ ls
sample.txt xx00 xx01
$ cat xx00
Line 1
Line 2
Line 3
Line 4
$ cat xx01
Line 5
Line 6
Line 7
Line 8
Line 9
Line 10
link:/cgi-bin/printpage.cgi [__印刷]