Unzip the input file using shell script (ksh)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Unzip the input file using shell script (ksh)
# 1  
Old 09-29-2010
Unzip the input file using shell script (ksh)

Hi,
I need help in unziping input file through shell script.
I had written script, which checks for input file extention.
If Extension is "zip" or "gz", then I want to do unzip/uncompress that file.
Caould you please let me know that, How to unzip a file through shell script (ksh).

Thanks in advance.Smilie
# 2  
Old 09-29-2010
Code:
gzip -d  # uncompress gz file
unzip # unzip zip file

# 3  
Old 09-29-2010
Thanks for the reply.

i had written as,

if [ $EXTN == "zip" ]; then
unzip $FILE
elif [ $EXTN == "gz" ]; then
gzip -d $FILE
elif [ $EXTN == "CSV" ]; then
// doing lots of things
// like parsing file line by line.

I just want to ask one question that,
I need to work on CSV file.If we unzip/uncrompress the file will it be stored in $FILE as extension is "CSV"?
# 4  
Old 09-29-2010
no, it will generate a new file.

for example, a file named as abc.gz, after gzip -d abc.gz, you will get a file named: abc

sometimes, the original file will be deleted automatically.
# 5  
Old 09-29-2010
But if I zip a .CSV file then what happen. After extraction it should be abc.CSV right?

So unzip $FILE will extract file into .CSV, so this changed name should I get into the $FILE or I need to assign it to variable like inputfile=`unzip $FILE` ?
# 6  
Old 09-29-2010
normally gzip will keep the orig file name in new filename, so is the file is abc.csv, after gzip, the file name will be abc.csv.gz, then when uncompress it, the file name will be back to abc.csv

In this case, if you manually rename the gz file from abc.csv.gz to abc.xyz.gz, and uncompress it, you will get file name as abc.xyz

but zip command not, you need provide the dest filename when zip it, after unzip, the orig file name will be always restored.
# 7  
Old 09-29-2010
Thanks a lot Smilie

Should I write FILE = unzip $FILE? will it work to store file name in same variable?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to get the shell script to read the .txt file as an input/data?

i have written my shell script in notepad however i am struggling to pass the data file to be read to the script the data file is of .txt format. My target is to run the shell script from the terminal and pass 3 arguments e.g. polg@DESKTOP-BVPDC5C:~/CS1420/coursework$ bash valsplit.sh input.txt... (11 Replies)
Discussion started by: Gurdza32
11 Replies

2. Ubuntu

How to lock a file through UNIX KSH shell script?

I wrote two shell scripts in UNIX that renames the same file and scheduled them at the same time. The following are the steps that I followed:- 1. I wrote 2 scripts named s1.sh and s2.sh, both trying to add “exec_” prefix to the name of the files present in a folder i which already don't start... (4 Replies)
Discussion started by: piuli
4 Replies

3. Shell Programming and Scripting

Using Shell Script in place of Perl script to Unzip the zip files.

Hi Expert, We have some shell scripts which Internally uses Perl Script to Unzip the source zip files which comes to inbound directory. So now our requirement is to avoid the dependency on Perl Script and us Shell Script to unzip the files. I have the Perl script with me attached can some one... (3 Replies)
Discussion started by: naveen.dasu
3 Replies

4. UNIX for Dummies Questions & Answers

File Inbound/Outbound shell script(ksh)

URGENT ---------- Post updated at 04:26 AM ---------- Previous update was at 04:23 AM ---------- (I could not post I didn't know why so I need to put the contents via reply, sorry) Hi all :D, I am a newbie of Unix shell script and I was assigned the work from user that I need to... (3 Replies)
Discussion started by: gogkub
3 Replies

5. Shell Programming and Scripting

Shell Script - File Input/Output in C

This is part of my code: for in_file in $1/*.in # list of all .in files in working directory. do $c_file < $in_file > "$tempFile.out" if diff "$tempFile.out" $out_file >/dev/null 2>&1 ; then ... (6 Replies)
Discussion started by: spider-man
6 Replies

6. Shell Programming and Scripting

shell script to add input at certain location into a file

Hi, I am using Solaris 10 OS and trying to create shell script that can add input at certain location into a file. The input that I am trying to put is new domain name e.g @newdomain.com the file contains, more test01.out user/zzzz786@st.com/INBOX user/zzzz@po.com/INBOX... (8 Replies)
Discussion started by: Mr_47
8 Replies

7. Shell Programming and Scripting

How to unzip files from folder in shell script (ksh)?

I have a folder (C:\shellprg\input\) containing .CSV, .zip, .gz files. 1] I want to find all .zip/.gz files from folder (C:\shellprg\input\). 2] unzip/uncompress files into the same folder (C:\shellprg\input\) through shell script. I am using below commands for unzip files, unzip <filename>... (2 Replies)
Discussion started by: Poonamol
2 Replies

8. Shell Programming and Scripting

How to write shell script for input file name format checking?

Hello, I had written a shell script that accepts input file as cmd line argument and process this file. if ; then if ; then . $1 LOGFILE="$LOG_FILE/MIG_BIOS.log"; get_input_file else ERROR_CODE=MSCRM0005_003 error "$ERROR_CODE : Input file $1 is not available"; exit... (3 Replies)
Discussion started by: Poonamol
3 Replies

9. Shell Programming and Scripting

Shell script for unzip

All, I'm having 4 .zip files that are coming from FTP. I need to unzip those files and put that files into another folder. Can anyone help me how to write a shell script to check wether .zip files are located in FTP folder, if condition true then how to unzip and put it in another folder. Thanks in... (2 Replies)
Discussion started by: nvkuriseti
2 Replies

10. Shell Programming and Scripting

Shell Script Menus - Rejecting invalid input (KSH)

Greetings all, I'm currently writing a shell script menu which is dynamically populated from an array. Have a question to ask about the filtering of invalid input. I'm using KSH. A brief description of my algorithm is as follows: 1) Read in input from user and store in a variable. (a valid... (2 Replies)
Discussion started by: rockysfr
2 Replies
Login or Register to Ask a Question