zcat two files

Hi,

Like

cat file1 file2 > file

Can I do

zcat file1.gz file2.gz > file.gz

why didn't you try your self ...:slight_smile:

and answer is NO.... you can't create .gz files like this..

if we can, just think what is use of gzip ...?????

1 Like

Hi Pamu,

Thanks for your advice. I have more than 10 files each of 20GB.

I wanted to confirm before trying it. But, anyways I figured out that you first zcat multiple files into another file and gzipping it rather than directly printing into a gz file. :slight_smile:

You can do cat file1 file2 | gzip > file.gz

...but you can't cat gz files.

You could if you decompressed them I suppose, but that'd have a lot of overhead.

1 Like

but we can use zcat .

zcat file_1.gz file_2.gz | gzip > output.gz

EDIT:
tried binlib suggestion and it also works...:slight_smile:

cat file_1.gz file_2.gz  > output.gz

and we can append data directly into gz file also....

cat file_3.gz >> output.gz
cat file | gzip >> output.gz
1 Like

Actually you CAN cat gz files and the result is a valid gzip file.

1 Like

Hi, binlib.

Commentt:

My experience is that unzipping the combined file results in the constituent files being effectively catted together.

If that is true, then your observation is correct, but it may not be useful in many situations ... cheers, drl

1 Like

Well, yes; that's kind of the point. :slight_smile:

I hadn't believed gzip would be capable of this -- gz file essentially has to catch the file starting over -- but it certainly appears to work.

This trick also works with bzip2, xz, and lzop ( though the latter warns about a multipart file ) -- but not with p7zip, lzma, or old-fashioned compress.

Hi, Corona688.

I'm not sure that we're talking about the same thing.

One rarely cats files together -- we keep files separate to distinguish something that characterizes the content. If we unzip a file that was created from a number of gz files, then the result is one huge file, with no way to distinguish among the data in the original files. If we want that, then it seems slightly easier to cat the raw files together, then gzip that file.

I suppose there might situations where we don't care about the separation -- where the content might effectively allow the data to be separated if necessary, date/time data for example, one data file after another, eliminating the need to gzip the entire file time after time. I haven't seen the need for that in my work, but I can easily imagine that there are such situations.

Best wishes ... cheers, drl

...except this OP. Taking it at face value, that's really, genuinely, and unambiguously what they want.

cat dogging you?

Hi.

OK, apparently only ambiguous to me :slight_smile: -- no more quibbles on this thread from me ... cheers, drl