-n, --number=CHUNKS generate CHUNKS output files; see explanation below
CHUNKS may be:
N split into N files based on size of input
K/N output Kth of N to stdout
l/N split into N files without splitting lines/records
l/K/N output Kth of N to stdout without splitting lines/records
r/N like 'l' but use round robin distribution
r/K/N likewise but only output Kth of N to stdout
$ split --help
Usage: split [OPTION] [INPUT [PREFIX]]
Output fixed-size pieces of INPUT to PREFIXaa, PREFIXab, ...; default
size is 1000 lines, and default PREFIX is `x'. With no INPUT, or when INPUT
is -, read standard input.
Mandatory arguments to long options are mandatory for short options too.
-a, --suffix-length=N use suffixes of length N (default 2)
-b, --bytes=SIZE put SIZE bytes per output file
-C, --line-bytes=SIZE put at most SIZE bytes of lines per output file
-d, --numeric-suffixes use numeric suffixes instead of alphabetic
-l, --lines=NUMBER put NUMBER lines per output file
--verbose print a diagnostic to standard error just
before each output file is opened
--help display this help and exit
--version output version information and exit
$ split --help
Usage: split [OPTION]... [INPUT [PREFIX]]
Output fixed-size pieces of INPUT to PREFIXaa, PREFIXab, ...; default
size is 1000 lines, and default PREFIX is `x'. With no INPUT, or when INPUT
is -, read standard input.
Mandatory arguments to long options are mandatory for short options too.
-a, --suffix-length=N use suffixes of length N (default 2)
-b, --bytes=SIZE put SIZE bytes per output file
-C, --line-bytes=SIZE put at most SIZE bytes of lines per output file
-d, --numeric-suffixes use numeric suffixes instead of alphabetic
-l, --lines=NUMBER put NUMBER lines per output file
--verbose print a diagnostic just before each
output file is opened
--help display this help and exit
--version output version information and exit
SIZE may have a multiplier suffix:
b 512, kB 1000, K 1024, MB 1000*1000, M 1024*1024,
GB 1000*1000*1000, G 1024*1024*1024, and so on for T, P, E, Z, Y.
10 回答
如果您只想将每个文件的x行分开,则给出的关于
split
的答案都可以 . 但是,我很好奇没有人关注要求:"without having to count them" - >使用wc cut
"having the remainder in extra file" - >默认情况下拆分
没有“wc cut”我不能那样做,但我正在使用它:
这可以很容易地添加到你的bashrc函数中,这样你就可以调用它来传递文件名和块:
如果您只想在额外文件中使用没有余数的x块,只需调整公式以对每个文件求和(块 - 1) . 我确实使用这种方法,因为通常我只需要x个文件而不是每个文件x行:
您可以将其添加到脚本中并将其称为“忍者方式”,因为如果没有满足您的需求,您可以构建它:-)
使用:
这里,1和100是您将在
output.txt
中捕获的行号 .split
(来自GNU coreutils,因为version 8.8 from 2010-12-22)包含以下参数:因此,
split -n 4 input output.
将生成具有相同字节数的四个文件(output.a{a,b,c,d}
),但中间可能会断行 .如果我们想保留整行(即按行分割),那么这应该有效:
相关回答:https://stackoverflow.com/a/19031247
split命令怎么样?
你也可以使用awk
你看过split命令了吗?
你可以这样做:
这将创建文件,每个文件有200000行名为
xaa xab xac
...另一个选项,按输出文件的大小分割(仍然在换行符上拆分):
创建像
output_prefix01 output_prefix02 output_prefix03 ...
这样的文件,每个文件最大大小为20兆字节 .是的,有一个
split
命令 . 它将按行或字节拆分文件 .将文件“file.txt”拆分为10000行文件:
使用
split
Syntax split [options] [INPUT [PREFIX]]
http://ss64.com/bash/split.html
HDFS getmerge小文件并溢出到属性大小 .
此方法将导致换行
split -b 125m compact.file -d -a 3 compact_prefix
我尝试getmerge并分成每个文件大约128MB .
分成128m,判断sizeunit是M还是G,请在使用前测试 .