2

Suppose I have a large zip file (>50GB) and I want to extract some files off of it from the command line.

To get the files I run the command:

unzip -l myfile.zip | grep "foo"

which gives me a list of zip entries; how do I extract those files that pass through the grep filter? I tried using xargs unzip -j but I'd like some cleaner solution as the zip entries require cleaning of useless information.

Warrior
  • 153
  • 1
  • 2
  • 6

1 Answers1

6

Stéphane has the right idea to pass zip the wildcard corresponding to the filenames that you'd like to extract. Parsing the output of unzip means you have to watch out for the header and trailer lines that come along.

Use something like:

unzip -j myfile.zip '*foo*'

being careful to quote the wildcards from the shell.

If you continue along the direction of grepping unzip's output, strip out the header and trailer and reduce it to the filename column:

unzip -l myfile.zip | sed '1,3d; /---------                     -------/d; $d'|cut -c31-
Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255