问题描述
我有一个巨大的gzip文件(〜400MB).我想在文件的开头添加一行文本.
I have a huge gzip file (~400MB). I want to append one line of text at the BEGINNING of the file.
我想创建一个带有标题行的 gzip 文件,然后使用 zcat
组合头文件和日志文件.只是想检查是否有更好/更优雅/更有效的方法.
I was thinking of creating a gzip file with the header line and then using zcat
to combine header file and log file. Just wanted to check if there is a better/elegant/efficient way to do it.
推荐答案
串联到单个文件的两个压缩文件实际上是有效的gz文件.
two gzipped files concatenated to a single file is actually a valid gz file.
尝试一下.
将您想添加的第一行单行压缩,然后将第二行扩展到第三行.
Gzip your first, single line that you want to prepend, then cat the two to a third.
print "My newline" | gzip -c > /tmp/smallzip.gz
cat /tmp/smallzip.gz mybigfile.gz > newbigfile.gz
这将节省解压缩大gz文件,在行之前加上并重新压缩的时间和cpu,这将是:
That would save the time and cpu of unzipping the big gz file, prepending your line and rezipping, which would be:
(
echo "My newline"
zcat bigfile.gz
) | gzip -c > newbifile.gz
这篇关于在巨大的gzip文件顶部追加一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!