Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

First the specific problem: In linux, I use zcat to list a .zip file. In osx, zcat seems to automatically append .Z to the file name. Various people suggest replacing zcat with gzcat; however, gzcat complains that the file is not in gzip format!

'file ' shows this: ...Zip archive data, at least v2.0 to extract

So neither zcat or gzcat will work in osx, what can I do?

I have a medium sized script in in bash which uses, zcat/gzcat, sed awk and other basic utilities to process a number of files. I'd like to duplicate that environment on my osx laptop so I can work offline. Any general suggestions how I can avoid such pain? I expect this is a fairly routine workflow so must have been sorted out by others.

share|improve this question
1  
If it's Zip archive data, it's not in gzip format! –  Michael Hampton Jan 27 at 0:48
    
@MichaelHampton I can zcat on linux fine. Neither zcat nor gzcat works on osx. So how can I resolve this? Is there another set of utilities I can install which will work both on linux as well as osx? These scripts are my own so I can change them (although I'd like to keep them simple). I control both linux/osx environments as well so I can do simple installs on both as well. –  user23398 Jan 27 at 3:25
    
I wouldn't say it's routine. I generally use zip to deal with zip files, not gzip. –  Michael Hampton Jan 27 at 3:39

3 Answers 3

You are right. It's annoying behavior.

$ zcat foo.txt.gz 
zcat: can't stat: foo.txt.gz (foo.txt.gz.Z): No such file or directory

Try this:

$ zcat < foo.txt.gz 
asdfadsf
share|improve this answer

The Mac OS X version of gzip(1) doesn't support reading zip files. From the man page:

This version of gzip is also capable of decompressing files compressed using compress(1) or bzip2(1).

But the Linux (GNU) version does.

gunzip can currently decompress files created by gzip, zip, compress, compress -H or pack.

Third parties have packaged GNU gzip for Mac OS X; you can find these from a web search. That is probably the path of least resistance.

share|improve this answer

You can install GNU utils for Mac OS X, e.g., using homebrew (run brew install coreutils gnu-sed, which installs gzcat et al. and gsed). This will provide you with the GNU implementation of each command.

Then, to make your life easier, make a variable for each command (e.g. sed=gsed, and use $sed subsequently), or simply alias them (e.g. alias sed=gsed) in any script you write. I've written a Gist on this for your convenience: gnu-tools-for-mac.sh. Put (or include) this code on top of your scripts.

Use the GNU implementation for both compressing and extracting the archives. I'd say you can't mix the uses of the OS X and GNU implementation.

share|improve this answer
    
You can alternatively add /usr/local/opt/coreutils/libexec/gnubin to your PATH, which will make them available without the g prefix. –  bfontaine Jul 7 at 17:56

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.