如何拆分大文件?
Posted
技术标签:
【中文标题】如何拆分大文件?【英文标题】:How can I split large files? 【发布时间】:2012-05-13 11:34:00 【问题描述】:我有一个大的 CSV 文件(7.3GB;16,300,000 行),如何将这个文件分成两个文件?
【问题讨论】:
【参考方案1】:您看过split
命令吗?有关详细信息,请参阅 this man 页面。
page 包含此命令的示例用法。
旁白:
如果您不太确定具体的命令是什么,man -k
命令对于查找 unix/linux 命令非常有用。使用 man -k 命令指定关键字,系统会拉出相关命令。例如,
% man -k split
将产生:
csplit (1) - split a file into sections determined by context lines
dirsplit (1) - splits directory into multiple with equal size
dpkg-split (1) - Debian package archive split/join tool
gpgsplit (1) - Split an OpenPGP message into packets
pnmsplit (1) - split a multi-image portable anymap into multiple single-image files
ppmtoyuvsplit (1) - convert a portable pixmap into 3 subsampled raw YUV files
split (1) - split a file into pieces
splitdiff (1) - separate out incremental patches
splitfont (1) - extract characters from an ISO-type font.
URI::Split (3pm) - Parse and compose URI strings
wcstok (3) - split wide-character string into tokens
yuvsplittoppm (1) - convert a Y- and a U- and a V-file into a portable pixmap
zipsplit (1) - split a zipfile into smaller zipfiles
【讨论】:
@spk:语法是正确的,但这会将您的文件拆分为 3,260,000 个文件。您应该选择一个更高的值,任何高于 8,150,000 且小于 16,300,000 的金额都会创建两个文件。 就像@spk 提到的那样,选择正确的值可以满足您的需求。如果您在 SO 上提出的任何问题为您的问题提供了正确答案,请随时接受 - meta.stackexchange.com/questions/5234/… 使用split
分割CSV文件时,注意每个文件的CSV头不重复。【参考方案2】:
split -d -n l/N 文件名.csv tempfile.part。
将文件拆分为 N 个文件而不拆分行。正如上面的 cmets 中提到的,每个文件中的 header 都不会重复。
【讨论】:
以上是关于如何拆分大文件?的主要内容,如果未能解决你的问题,请参考以下文章