csplit
rose1 发表于 2020-08-19 11:15浏览次数:
在类似Unix的操作系统上,csplit命令根据上下文行将文件拆分为多个部分。
本文档介绍ucsplit的GNU / Linux版本。
On Unix-like operating systems, the csplit command splits a file into sections, based on context lines.
This document covers the GNU/Linux version of ucsplit.
目录:
1 csplit 运行系统环境
2 csplit 说明
3 csplit 语法
4 csplit 例子
csplit 运行系统环境
csplit 说明
csplit将用PATTERN分隔的FILE文件输出到文件' xx00 ',' xx01 ',...,并将每段的字节数输出到标准输出。
csplit outputs pieces of FILE separated by PATTERN(s) to files 'xx00', 'xx01', ..., and output byte counts of each piece to standard output.
csplit 语法
csplit [OPTION]... FILE PATTERN...
选件
|
-b, --suffix-format=FORMAT
|
使用sprintf FORMAT代替%02d。
|
|
-f, --prefix=PREFIX
|
使用PREFIX代替“ xx ”。
|
|
-k, --keep-files
|
不要在错误时删除输出文件。
|
|
-n, --digits=DIGITS
|
使用指定的数字位数,而不是2。
|
|
-s, --quiet, --silent
|
不打印输出文件大小的计数。
|
|
-z, --elide-empty-files
|
删除空的输出文件。
|
|
--help
|
显示帮助消息并退出。
|
|
--version
|
输出版本信息并退出。
|
如果将FILE指定为破折号(“ - ”),则csplit读取标准输入。每个模式可以是:
|
INTEGER
|
复制最多但不包括指定的行号。
|
|
/REGEXP/[OFFSET]
|
复制最多但不包括匹配行。
|
|
%REGEXP%[OFFSET]
|
跳至但不包括匹配行。
|
|
{INTEGER}
|
重复前一个模式指定的次数。
|
|
{*}
|
尽可能重复上一个模式。
|
行OFFSET是必需的' + '或' - ',后跟一个正整数。
csplit [OPTION]... FILE PATTERN...
Options
|
-b, --suffix-format=FORMAT
|
use sprintf FORMAT instead of %02d.
|
|
-f, --prefix=PREFIX
|
use PREFIX instead of 'xx'.
|
|
-k, --keep-files
|
do not remove output files on errors.
|
|
-n, --digits=DIGITS
|
use specified number of digits instead of 2.
|
|
-s, --quiet, --silent
|
do not print counts of output file sizes.
|
|
-z, --elide-empty-files
|
remove empty output files.
|
|
--help
|
display a help message and exit.
|
|
--version
|
output version information and exit.
|
csplit reads standard input if FILE is specified as a dash ("-"). Each PATTERN may be:
|
INTEGER
|
copy up to but not including specified line number.
|
|
/REGEXP/[OFFSET]
|
copy up to but not including a matching line.
|
|
%REGEXP%[OFFSET]
|
skip to, but not including a matching line.
|
|
{INTEGER}
|
repeat the previous pattern specified number of times.
|
|
{*}
|
repeat the previous pattern as many times as possible.
|
A line OFFSET is a required '+' or '-' followed by a positive integer.
csplit 例子
csplit -f cobol filename '/procedure division/' /par5./ /par16./
创建四个文件cobol00 ... cobol03。
编辑拆分文件后,可以使用cat命令将它们重新组合为文件名,如下所示:
cat cobol0[0-3] > filename
csplit -f cobol filename '/procedure division/' /par5./ /par16./
Creates four files, cobol00...cobol03.
After editing the split files, they can be recombined into filename using the cat command as follows:
cat cobol0[0-3] > filename