Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'd like to gunzip a directory full of compressed files and pipe the output (preserving the original files) to a different directory. I need the original names to stay the same. So...

gunzip -c *.gz > file/path/filename 

# Search for all .gz in current directory and redirect output here. How do I grab the name of the file found using the wildcard?

Thank you for your help

Update: Final script below

FILES= /foo/bar/*.gz
for gz in $FILES; do
echo "unzipping $gz..." 1>&2
fn=$(basename $gz .gz)
gunzip -c $gz > /new/foobar/$fn
done
share|improve this question

migrated from stackoverflow.com Jun 21 '13 at 23:58

This question came from our site for professional and enthusiast programmers.

    
What does this have to do with Python? Also, what do you mean by "preserving the original files"? –  Blender Jun 21 '13 at 18:39
    
Apologies; just writing python, it was on the brain. What I mean by preserving original files is that gunzip typically deletes the compressed file and outputs a file that is not compressed (hence the -c flag) –  KennyC Jun 21 '13 at 18:42

2 Answers 2

up vote 1 down vote accepted

You may want to use a shell script instead:

for f in *.gz
do
    zcat "$f" > "other/folder/$(basename "$f" ".gz")"
done
share|improve this answer

With GNU Parallel you can do:

parallel gunzip -c {} '>' /new/foobar/{/.} ::: /foo/bar/*.gz

GNU Parallel takes literally 10 seconds to install:

wget pi.dk/3 -qO - | sh -x

Watch the intro videos to learn more: https://www.youtube.com/playlist?list=PL284C9FF2488BC6D1

share|improve this answer
    
Installed GNU Parallel but am getting this error; parallel: Warning: Input is read from the terminal. Only experts do this on purpose. Press CTRL-D to exit. Is it a syntax problem? Can you provide insight with the edited script in the question? –  KennyC Jun 24 '13 at 16:03
    
Post output of 'parallel --version'. If you did not install as mentioned above, you might be hit by stackoverflow.com/questions/16448887/… –  Ole Tange Jun 24 '13 at 17:00
    
Installed as above; no mention of tollef GNU parallel 20130622 –  KennyC Jun 24 '13 at 17:40
    
If it works with '--gnu' then you have a '--tollef' somewhere. –  Ole Tange Jun 24 '13 at 18:08

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.