I have a huge gzip file (~400MB). I want to append one line of text at the BEGINNING of the file.
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.
two gzipped files concatenated to a single file is actually a valid gz file.
Try it.
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With