Linux的split命令可以用来分割文件
-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
SIZE may have a multiplier suffix: b for 512, k for 1K, m for 1 Meg.
可以用一个简单的python脚本将指定的文件分割成几个大小和条数近似相同的文件:
代码如下:
import os
def _split_file(filepath,theFileNumber):
filesize = __file_size(filepath)
slavelength = theFileNumber
splitsize = filesize/slavelength + 1000 //这里大小加上1000个字节,保证最后一个分割的文件不会丢数据
command = " split -C %d %s %s%s" % (splitsize, filepath, prefix,filepath[filepath.rfind("/")+1:]) //其实使用的就是liunx的split
print command
os.system(command)
def __file_size(filepath):
statinfo=os.stat(filepath)
return statinfo.st_size
if __name__ == "__main__":
dataFilePath="/data/big_file.log"
_split_file(dataFilePath,4)
分享到:
相关推荐
0139 使用FileExists函数判断指定文件是否存在 90 0140 使用FileGetAttr函数返回文件的属性 90 0141 使用FileGetDate函数返回文件的修改日期 90 0142 使用FileWrite函数将缓冲区中的内容写入文件 91 4.10 ...
0139 使用FileExists函数判断指定文件是否存在 90 0140 使用FileGetAttr函数返回文件的属性 90 0141 使用FileGetDate函数返回文件的修改日期 90 0142 使用FileWrite函数将缓冲区中的内容写入文件 91 4.10 ...
实例199 文件分割 284 实例200 文件加密 286 第7章 库函数调用 289 7.1 时间转换和操作函数 290 实例201 固定格式输出当前时间 290 实例202 当前时间转换 291 实例203 显示程序运行时间 292 实例204...
1.23 能否声明和传入数组大小一致的局部数组,或者由其他参数指定大小的参数数组? 13 1.24 我在一个文件中定义了一个extern数组,然后在另一个文件中使用,为什么sizeof取不到数组的大小? 13 声明问题 14 ...
6.22 如何在一个文件中判断声明为extern的数组的大小(例如,数组定义和大小在另一个文件中)?sizeof操作符似乎不行。 6.23 sizeof返回的大小是以字节计算的,怎样才能判断数组中有多少个元素呢? 第7章 内存...