Unzip the Files


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Unzip the Files
# 8  
Old 10-02-2012
Quote:
Originally Posted by eskay
I am really dummy at unix so I really go with single line commands. I use this commands in the IBM ETL tool.

I do not know how to use
Code:
for i in *.zip
do      if unzip $i
        then rm $i
        fi
done

is i the file name?
like

for filename in filepath ? I have to define the variables right?
I generally prefer "readable" to "fits on one line", but if you want a single line UNIX command, here it is:
Code:
for i in *.zip;do if unzip $i;then rm $i;fi;done

Type this command into your shell (assuming that you use a POSIX compatible shell such as ksh, or bash) in the directory (AKA folder) where you have placed the zip files. The shell will execute a loop of commands once for each zip file in that directory setting the shell variable i to the pathname of one of your zip files. In the loop it will use the unzip utility to extract all of the files in that zip file, and then, if and only if it successfully extracts all of the files in the zip file, it will then remove the zip file.

Hope this helps,
Don
# 9  
Old 10-03-2012
Quote:
Originally Posted by eskay
I am really dummy at unix so I really go with single line commands.
The difference between single line commands and multiple line commands is the return key. Cramming it all on one line for no reason just makes it harder.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Unzip all the files with subdirectories present and append a part of string from the main .zip files

Hi frnds, My requirement is I have a zip file with name say eg: test_ABC_UH_ccde2a_awdeaea_20150422.zip within that there are subdirectories on each directory we again have .zip files and in that we have files like mama20150422.gz and so on. Iam in need of a bash script so that it unzips... (0 Replies)
Discussion started by: Ravi Kishore
0 Replies

2. Shell Programming and Scripting

Script to unzip files and Rename the Output-files

Hi all, I have a many folders with zipped files in them. The zipped files are txt files from different folders. The txt files have the same names. If i try to find . -type f -name "*.zip" -exec cp -R {} /myhome/ZIP \; it fails since the ZIP files from different folders have the same names and... (2 Replies)
Discussion started by: pmkenya
2 Replies

3. Shell Programming and Scripting

Unzip the .zip file without using unzip utility in UNIX

I have .zip file, i want to list all the files archived in the zip file. unzip utility is not working for me in unix. Please help me resolve this issue Thanks ganesh. (3 Replies)
Discussion started by: Ganesh L
3 Replies

4. Shell Programming and Scripting

How to Unzip a file using unzip utility for files zipped without zip utility ?

Hi, I need to zip/compress a data file and send to a vendor. The vendor does have only unzip utility and can accept only .ZIP files. I do not have zip utility in my server. How do I zip/compress the file so that it can be deflated using unzip command ? I tried gzip & compress commands, but... (1 Reply)
Discussion started by: Sabari Nath S
1 Replies

5. Shell Programming and Scripting

How to Unzip a .ZIP file in Unix without using unzip cmd..?????

Hi All I have ftped a .ZIP file (zipped using WinZip in Windows) to my Unix server (HP-UX). I don't have unzip cmd available in my curent Unix version Please let me know any cmd in UNIX (other than unzip) using which I can unzip this .ZIP file . Please elaborate on the commands aval and... (5 Replies)
Discussion started by: sureshg_sampat
5 Replies

6. UNIX for Dummies Questions & Answers

unzip files in a different folder

hi , I am using this command to unzip files from a source unzip -o $source_dir -d $dest_dir butthe problem is that this command creates a new folder at the destination and unzips all the files in that folder. I dont want that extra folder. e.g source_dir= abc/myname.zip... (2 Replies)
Discussion started by: agarwalniru
2 Replies

7. Shell Programming and Scripting

unzip particular gzip files among the normal data files

Hello experts, I run Solaris 9. I have a below script which is used for gunzip the thousand files from a directory. ---- #!/usr/bin/sh cd /home/thousands/gzipfiles/ for i in `ls -1` do gunzip -c $i > /path/to/file/$i done ---- In my SAME directory there thousand of GZIP file and also... (4 Replies)
Discussion started by: thepurple
4 Replies

8. HP-UX

How to Unzip a .ZIP file in Unix without using unzip cmd..?????

Hi All I have ftped a .ZIP file (zipped using WinZip in Windows) to my Unix server (HP-UX). I don't have unzip cmd available in my curent Unix version Please let me know any cmd in UNIX (other than unzip) using which I can unzip this .ZIP file . Please elaborate on the commands aval and... (5 Replies)
Discussion started by: sureshg_sampat
5 Replies

9. UNIX for Dummies Questions & Answers

Copy files from CD and Unzip

Hi, I've just installed solaris 9 onto a SPARC box and am connecting to the machine via a console cable using hyper terminal. Unfortunately i have not got a monitor so i'm having to do all my config using the command line (which i'm no good at) I'm trying to copy a patch cluster (ZIP) file... (1 Reply)
Discussion started by: AJD
1 Replies

10. UNIX for Dummies Questions & Answers

unzip .tgz files

hi all How to unzip .tgz files waiting for suggestions Praful (5 Replies)
Discussion started by: Prafulla
5 Replies
Login or Register to Ask a Question