免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2365 | 回复: 0
打印 上一主题 下一主题

Linux的split命令可以用来分割文件 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-04-11 13:37 |只看该作者 |倒序浏览
-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)
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP