Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Gzip

Posted on 2010-09-17
19
Medium Priority
?
614 Views
Last Modified: 2013-12-06
Just wondering how I can zip up two files into one file.gz ?

Currently I only know how to do one at a time. gzip -9 file.vmd file2.vmdk

Any suggestions?
0
Comment
Question by:snyderkv
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 6
  • 3
  • +1
19 Comments
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 1000 total points
ID: 33704628
cat file1 file2 | gzip > file3.gz

or

gzip -c file1 > file3.gz
gzip -c file2 >> file3.gz

wmp
0
 
LVL 4

Assisted Solution

by:Tachion
Tachion earned 500 total points
ID: 33705189
The "problem" with the previously suggested solution is that the result is a concatenated, zipped file.

You may be looking for "zip" instead of "gzip". The zip utility behaves more like the "other operating system" utility in that it archives as well as compresses.

Alternatively, use tar with compression.

tar czvf files.tgz file.vmd file2.vmd

0
 
LVL 35

Assisted Solution

by:Duncan Roe
Duncan Roe earned 500 total points
ID: 33705719
Agree with Tachion - gzip is only a file compressor while zip is an archiver and file compressor combined as is tar -cz (or you can run the tar and gzip functions in separate steps)
0
Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

 

Author Comment

by:snyderkv
ID: 33706733
Cool thanks guys, but the reason I think I needed to use gzip was that when uncompressing within ESX linux, It has gzip built in I think. Unless gzip can decompress zip?
0
 

Author Comment

by:snyderkv
ID: 33706742
And whats wrong with concantaining the files? I just need them both compressed into one file and uncompress back into two files. This wouldn't cause an issue with the data would it?
0
 

Author Comment

by:snyderkv
ID: 33706912
gzip -c file > file2.txt didn't work . I'm using gzip if that makes a difference.

Closing
0
 
LVL 35

Expert Comment

by:Duncan Roe
ID: 33707477
Windows gzip should be no different to Linux gzip. But do you have Windows tar?
"whats wrong with concantaining the files?" - nothing, as long as you realise that gunzip will give you one concatenated file rather than the 2 files you started with. It will not resolve back yo 2 files, which looks like what you hoped for.
Odd that gzip -c file > file2.txt didn't work. Does it work if you do gzip -c file > file2.gz? (you can compare with the file you get from simply gzip file - that will make file.gz). Microsoft did try to implement unix constructs (like ">") in CMD.EXE but I don't know how good that implementation is. They might be inserting Cr before Lf for instance, especially to a .txt file.
0
 
LVL 4

Expert Comment

by:Tachion
ID: 33708402
The gzip -c file > file2.txt didn't work most likely because the file2.txt existed already.
If you read the first reply carefully, then you would notice that the lines include a double angle bracket: >>
This says "append to the existing file."

All versions of Linux come with gzip and tar, and the commands:

tar -czvf file.tgz file1.txt file2.txt

will put the two files into an archive and compress that archive using gzip. Which you intended. To unpack the whole thing and get two files back you use:

tar -czvf tile.tgz

Both files will come back as separate files. The first suggested method will return a single concatenated file.

Most versions of Linux will come with "zip" pre-installed as well, which may be the preferred method to use if you would want to use Windows to unpack the files. There are versions of "tar" as well that work on Windows (see http://gnuwin32.sourceforge.net/packages/gtar.htm). Zip and tar (and gzip) also come standard on Mac's.  

This really is what you asked for. I don't understand why you are closing.

0
 

Author Comment

by:snyderkv
ID: 33708449
Tach,

I accepted multiple solutons and for some reason it asked to close. I'm confused too.

I will try and award points again. Very helpfull answers everyone. I feel like a pro now.

Thanks again.
0
 
LVL 35

Expert Comment

by:Duncan Roe
ID: 33709730
Cool, you can concatenate gzips. I didn't know that before. But when you unzip, you get a single file which is the 2 original files concatenated, not really what was asked for.
snyderkv: I wouldn't worry about changing the points :)
10:40:27$ cat file1
This is file 1
10:42:37$ cat file2
This is file 2
10:46:29$ gzip -c file1 >bothfiles.gz
10:46:46$ gzip -c file2 >>bothfiles.gz
10:47:21$ ls -l
total 12
-rw-r--r-- 1 dunc users 78 Sep 19 10:47 bothfiles.gz
-rw-r--r-- 1 dunc users 15 Sep 19 10:40 file1
-rw-r--r-- 1 dunc users 15 Sep 19 10:40 file2
10:47:25$ rm file1 file2
10:47:55$ gunzip bothfiles.gz 
10:48:03$ ls -l
total 4
-rw-r--r-- 1 dunc users 30 Sep 19 10:47 bothfiles
10:48:07$ cat bothfiles 
This is file 1
This is file 2
10:48:14$ 

Open in new window

0
 
LVL 35

Expert Comment

by:Duncan Roe
ID: 33709772
Sorry it's not for me to suggest you don't change points. Tachion had the first correct answer - all I did was explain why it was correct.
I have posted this as an objection so you can re-assign as you wish.

Moderator - apologies for the noise
0
 
LVL 35

Expert Comment

by:Duncan Roe
ID: 33732691
Excuse me - woolmilkporc's comment is wrong. You can't accept that. snyderkv said he would try to award points again - so give him some time.
0
 
LVL 35

Expert Comment

by:Duncan Roe
ID: 33732710
snyderkv: please at least post how you would like the points allocated - even if you don't actually do it.
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 33732715
Taking the question literally my answer is not wrong.
0
 

Author Comment

by:snyderkv
ID: 33732726
Who said it was wrong?
0
 

Author Comment

by:snyderkv
ID: 33732731
Who said it was wrong? I tried splitting the points evenly. Someone may have objected. I don't know
0
 
LVL 68

Assisted Solution

by:woolmilkporc
woolmilkporc earned 1000 total points
ID: 33732742
Please look here: #33732691 , where duncan_roe wrote >> woolmilkporc's comment is wrong. You can't accept that <<
0

Featured Post

Congratulations! You’re Certified – Now What?

Starting a new career can be overwhelming. Becoming certified in your field of expertise is a great start, but where do you go from here?  Here are some tips to help you on your career journey.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The article will include the best Data Recovery Tools along with their Features, Capabilities, and their Download Links. Hope you’ll enjoy it and will choose the one as required by you.
Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will give…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Suggested Courses

660 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question