1

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
2
  • What does this have to do with Python? Also, what do you mean by "preserving the original files"?
    – Blender
    Jun 21, 2013 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, 2013 at 18:42

2 Answers 2

1

You may want to use a shell script instead:

for f in *.gz
do
    zcat "$f" > "other/folder/$(basename "$f" ".gz")"
done
0

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

4
  • 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, 2013 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, 2013 at 17:00
  • Installed as above; no mention of tollef GNU parallel 20130622
    – KennyC
    Jun 24, 2013 at 17:40
  • If it works with '--gnu' then you have a '--tollef' somewhere.
    – Ole Tange
    Jun 24, 2013 at 18:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .