Unzip individual files from multiple zip files and extract those individual files to home directory

15,677

Solution 1

For unzip command with range expression in filename, we need to escape both the range format and the wildcard in target filename, e.g. to unzip files with txt extension in order0710.zip, ... order0715.zip into folder txt_pool, we should issue command like this:

unzip -jn order071\[0-5].zip \*.txt -d txt_pool

Solution 2

I think you should also quote the * in the list of files. The command should looks something like that:

unzip -jn /path/to/zipped/files/zipArchiveFile2011\*.zip
      /path/to/specific/individual/files/myfiles2011\*.txt 
      -d /path/to/home/directory/for/extract/

If doesn't quote the second * bash expands it and place the files names. You can check the value which is passed to command by using echo:

echo /path/to/specific/individual/files/myfiles2011*.txt
Share:
15,677

Related videos on Youtube

fixer1234
Author by

fixer1234

Updated on September 18, 2022

Comments

  • fixer1234
    fixer1234 over 1 year

    I would like to unzip individual files. These files have a .txt extension. These files also live within multiple zipped files. Here is the command I'm trying to use.

    unzip -jn /path/to/zipped/files/zipArchiveFile2011\*.zip /path/to/specific/individual/files/myfiles2011*.txt -d /path/to/home/directory/for/extract/

    From my understanding, the -j option excludes directories and will extract only the txt files The -n option will not overwrite a file if it has already been extracted. I've also learned that the forward slash in /path/to/zipped/files/zipArchiveFile2011\*.zip is necessary to escape the wildcard (*) character.

    Here is sample of error messages I'm coming accross:

    Archive: /path/to/zipped/files/zipArchiveFile20110808.zip caution: filename not matched: /path/to/specific/individual/files/myfiles20110807.txt caution: filename not matched: /path/to/specific/individual/files/myfiles20110808.txt Archive: /path/to/zipped/files/zipArchiveFile20110809.zip caution: filename not matched: /path/to/specific/individual/files/myfiles20110810.txt caution: filename not matched: /path/to/specific/individual/files/myfiles20110809.txt

    I feel that I'm missing something very simple. I've tried using single quotes (') and double quotes (") around directory paths. But no luck.

    • shellter
      shellter over 12 years
      Simplfy your problem to get extracting from 1 file working, i.e. remove the star in the first, replace it with the fully qualified path/to/UniqFileName AND then quote any remaining * chars as you indicated (\*). You do want to extract 1 or more files matching the second pattern .../individual/files/... from the archive, right? When you understand how that is working, then you can figure out how to use shell wildcards to create a list of files that unzip will process all at once
  • Kruug
    Kruug over 11 years
    Just a head's up, he's using RedHat/Unix (hence the tags), not Windows. :)