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 have a .zip file (It contains multiple files, ex: file1.txt file2.txt file3.txt.. n so on) in a directory.

And my query is:

How to extract the files from .zip archive to the very same directory and how to create the list of all the files extracted from .zip archive.**

The extracted file name should be printed like this in the file named: file_list:

file1.txt
file2.txt
file3.txt
filen.txt

I have tried the following command assuming that my .zip file name is "data.zip".

unzip -qoj data.zip | unzip -ql data.zip  > file_list 

I have used unzip -qoj data.zip to extract all the files in the same directory(quietly,overwrite,junk_path). When I try to insert -l with the first unzip command then the command doesn't extract the file in the current and only files are listed thats why I have to used unzip again after the first pipe(If I am making a mistake here let me know please).

I get the following output

 Length     Date   Time    Name
 --------    ----   ----    ----
        0  12-21-09 14:25   data/
     6148  12-21-09 14:25   data/.DS_Store
        0  12-21-09 14:25   __MACOSX/
        0  12-21-09 14:25   __MACOSX/data/
       82  12-21-09 14:25   __MACOSX/data/._.DS_Store
       82  12-11-09 13:59   data/file1.txt
      120  12-11-09 13:59   data/file2.txt
      166  12-11-09 13:59   data/file3.txt
 --------                   -------
     6598                   8 files

How do I extract only file1.txt file2.txt file3.txt from this stdout?

Is it possible to do this with linux command or I have to write a perl script for this?

Thank you.

share|improve this question

migrated from stackoverflow.com Feb 24 '10 at 1:55

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

add comment

1 Answer

unzip data.zip data/file1.txt data/file2.txt data/file3.txt
share|improve this answer
    
what if I have 100 files in .zip archive? –  Suren Feb 23 '10 at 21:16
    
unzip -l data.zip|gawk '$NF~/^data\/file.\.txt$/{print $NF;}'|xargs unzip -qoj –  jch Feb 24 '10 at 16:10
add comment

Your Answer

 
discard

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