Home Man
Search
Today's Posts
Register

This forum is closed for new posts. Please post beginner questions to learn unix and learn linux in the UNIX for Beginners Questions & Answers forum.

unzip .zip file and list the files included in the .zip archive

Tags
archive, beginners, file, zip

 

 
Thread Tools Search this Thread
# 1  
Old 04-08-2008
unzip .zip file and list the files included in the .zip archive

Hello,
I am trying to return the name of the resulting file from a .zip archive file using unix unzip command.

unzip c07212007.cef7081.zip
Archive: c07212007.cef7081.zip
SecureZIP for z/OS by PKWARE
inflating: CEP/CEM7080/PPVBILL/PASS/G0063V00

I used the following command to unzip in quite mode (-q), without making directories(-j) and overwrite existing files(-o)

unzip - qjo c07212007.cef7081.zip

The above cmd unzippes the file "G0063V00" in the current working directory.

In addition to unzipping the file in the current working dir, I would like to store the filename resulting filename "G0063V00" in a variable for further processing. How do I get the filename that was just unzipped ? I tried using -l option but I get a lot more information than needed.

unzip -qjol c07212007.cef7081.zip

Length Date Time Name
-------- ---- ---- ----
265 07-22-07 03:32 CEP/CEM7080/PPVBILL/PASS/G0063V00
-------- -------
265 1 file

So I tried the following:

basename "`unzip -qojl c07212007.cef7081.zip`"

G0063V00
-------- -------
265 1 file


As you see, I still get more information than I need. I just want to return the filename which in this case is "G0063V00".

Thanks for you help in advance.
# 2  
Old 04-08-2008
you could sort by last modified, grab first entry into variable then echo out the variable.
# 3  
Old 04-08-2008
There are other processes concurrently creating files in the same directory.
# 4  
Old 04-08-2008
Code:
basename "`unzip -qojl c07212007.cef7081.zip | awk 'NR==3{print $4}'`"

maybe?
# 5  
Old 04-08-2008
Thanks ! That did the trick.

If you dont mind, can you briefly explain
awk 'NR==3{print $4}'

Thanks for you help !
# 6  
Old 04-08-2008
Fourth field of third line. See the awk manual page or any introductory Unix book for details.
 

« Previous Thread | Next Thread »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Cpio - input files (from list) are stored in different order inside cpio archive - why? am115998 UNIX for Advanced & Expert Users 1 03-02-2018 03:01 PM
Extract a list of files using unzip command remissssss Shell Programming and Scripting 6 03-31-2014 04:49 PM
Unzip the .zip file without using unzip utility in UNIX Ganesh L Shell Programming and Scripting 3 10-29-2013 04:56 AM
Zip a list of specific files to an archive Biggreuda Shell Programming and Scripting 3 04-24-2012 06:45 AM
How to Unzip a file using unzip utility for files zipped without zip utility ? Sabari Nath S Shell Programming and Scripting 1 12-11-2009 05:18 PM
unzip few files but with same path and file name. jimmy_y Shell Programming and Scripting 1 08-27-2009 11:20 PM
Unzip selected files in .tar.gz file trongkhuongsg Linux 1 05-05-2009 03:38 PM
How to Unzip a .ZIP file in Unix without using unzip cmd..????? sureshg_sampat Shell Programming and Scripting 5 11-15-2008 03:44 AM
read list of filenames from text file, archive, and remove fxvisions Shell Programming and Scripting 5 03-20-2007 09:56 PM
How to Unzip a .ZIP file in Unix without using unzip cmd..????? sureshg_sampat HP-UX 5 02-08-2007 09:01 AM


All times are GMT -4. The time now is 02:06 PM.

Unix & Linux Forums Content Copyrightę1993-2018. All Rights Reserved.
UNIX.COM Login
Username:
Password:  
Show Password