I have a recurring task of splitting a set of large (about 1-2 GiB each) gzipped Apache logfiles into several parts (say chunks of 500K lines). The final files should be gzipped again to limit the disk usage.

我有一个经常性的任务,即将一组大的(每个大约1-2 GiB)gzip压缩的Apache日志文件拆分成几个部分(比如说500K行的块)。应该再次压缩最终文件以限制磁盘使用。

On Linux I would normally do:

在Linux上我通常会这样做:

zcat biglogfile.gz | split -l500000

The resulting files files will be named xaa, xab, xac, etc So I do:

生成的文件文件将命名为xaa,xab,xac等。所以我这样做:

gzip x*

The effect of this method is that as an intermediate result these huge files are temporarily stored on disk. Is there a way to avoid this intermediate disk usage?

这种方法的效果是,作为中间结果,这些巨大的文件暂时存储在磁盘上。有没有办法避免这种中间磁盘使用?

Can I (in a way similar to what xargs does) have split pipe the output through a command (like gzip) and recompress the output on the fly? Or am I looking in the wrong direction and is there a much better way to do this?

我可以(以类似于xargs的方式)通过命令(如gzip)拆分输出并在运行中重新压缩输出吗?或者我是否朝错误的方向看,是否有更好的方法来做到这一点?

Thanks.

谢谢。

3 个解决方案

#1


19

You can use the slpit --filter option as explained in the manual e.g.

您可以使用slpit --filter选项,如手册中所述,例如:

zcat biglogfile.gz | split -l500000 --filter='gzip > $FILE.gz'

Edit: not aware when --filter option was introduced but according to comments, it is not working in core utils 8.4.

编辑:不知道何时引入了--filter选项但根据注释,它在核心工具8.4中不起作用。

更多相关文章

  1. 为什么Linux不需要磁盘碎片整理?——借以复习文件系统方面的知识
  2. Linux中的文件权限和用户组
  3. Linux学习之文件系统权限及表示
  4. linux 文件系统的管理 (硬盘) 工作原理
  5. Linux系统的文件传输工具RZSZ
  6. Linux:目录中的最新文件。
  7. 对于Linux创建链接时终目录和文件处理的认识
  8. Linux文件归档和解压缩
  9. 如何使用“tail -1 * / filename”拖尾多个文件的最后一行

随机推荐

  1. 用JavaScript实现二叉搜索树[每日前端夜
  2. 从.env文件中为NodeJS加载环境变量[每日
  3. Apollo 源码解析 —— Portal 创建灰度
  4. Apollo 源码解析 —— Portal 批量变更 I
  5. 怎样成为全栈开发工程师[每日前端夜话0xA
  6. 50个必须要会的微服务面试题[每日前端夜
  7. 前端网络知识点总结
  8. Apollo 源码解析 —— Config Service 操
  9. Apollo 源码解析 —— Admin Service 锁
  10. Spring 异步调用,一行代码实现!舒服,不接受