您的位置:首页 > 运维架构 > Shell

Shell Script : Join small gzipped files into larger files without unzipping them

2013-11-28 14:00 411 查看
I have some 8000 gz files of around 60MB each. I want to merge them into few larger files. So how to do it in a bash scriptwithout unzipping them ?

Shell script may take input as new-file-size or number of files to combine.

For example say I have 1.gz, 2.gz, 3.gz ... 10.gzNow I need one file per say 3 files, so now 1.gz, 2.gz and 3.gz will combine into 1_new.gz and so on.

Answer:

It is possible to concatinate
gzip
ed files together, however when you
gunzip
the resulting file you'll get a single stream, see the

gzip manual for reference.

A script would be similar to Ansgar Wiechers's one for
tar
:

#!/bin/bash

maxnum=$1
i=1
j=0
for f in *.gz; do
cat $f >> archive_$j.gz
i=$((i+1))
if [ $i -eq $maxnum ]; then
i=1
j=$((j+1))
fi
done


Note that the above code is untested.

If you want to archive things properly
tar
is a better solution, but if all you want to do is concatinate a number of files which have been
gzip
ed then such a concatination as this is good.

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: