I have 2 gz files those I need to merge into one -- that is to say I want to combine two .gz files into one such that when I extract the combined file I get a single file containing the concatenation of the original input files.
time join <(zcat r_TR2_2012-05-28-08-10-00.gz) <(zcat r_TR1_2012-05-28-08-10-00.gz)
The above statement is not working as expected. I am using 3 commands to do the needful.
gunzip r_TR2_2012-05-28-08-10-00.gz
gunzip r_TR1_2012-05-28-08-10-00.gz
tar -zcvf combined.tar.gz r_TR1_2012-05-28-08-10-00 r_TR2_2012-05-28-08-10-00
and then concatenating the files together when I extract them to produce the output I want.
Is there any way to do this in 1 statement?
I guess you mean:
zcat r_TR2_2012-05-28-08-10-00.gz r_TR1_2012-05-28-08-10-00.gz| gzip -9 > joined.gz
Surprisingly what Quanta posted in the comments works -- at least on my Mac!
I am somewhat disturbed, yet also impressed.
If you have multiple compressed files
.gz
and you need to combine them into one file, you can usetar
directly to do so. No need to uncompress and then compress them again.You can try this:
However, you will get a file with extension
.gz.tar
as opposed to the known.tar.gz
. To uncompress the file, you can try:The option -a is useful here (from
man tar
):