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

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 gziped files together, however when yougunzip 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 beengziped then such a concatination as this is good.


你可能感兴趣的:(Shell Script : Join small gzipped files into larger files without unzipping them)