如何在不拆分条目的情况下将 6 或 7 GB 文件拆分为多个小于 2 GB 的文件?

如何在不拆分条目的情况下将 6 或 7 GB 文件拆分为多个小于 2 GB 的文件?

我的关卡有 6 到 10 GB 大小的文件作为输入。这些文件包含多行数据。下一级的最大输入容量为2GB。所以我必须将这些 6-10 GB 的文件分割成几个低于 2 GB 的文件,而且不能断行!基本上我必须根据大小拆分文件,但不能断行。

答案1

如果您没有任何超过 2GB 的行,您可以使用

split --line-bytes=2GB

来自信息手册:

‘--line-bytes=SIZE’
 Put into each output file as many complete lines of INPUT as
 possible without exceeding SIZE bytes.  Individual lines or records
 longer than SIZE bytes are broken into multiple files.

答案2

我相信这几乎可以满足您的需求

split -n

-n, --number=CHUNKS
              generate CHUNKS output files.


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
l/K/N   output Kth of N to stdout without splitting lines
r/N     like 'l' but use round robin distribution
r/K/N   likewise but only output Kth of N to stdout

相关内容