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
It is easier with the "basename" command.

Code:
zipped="abc.csv.gz"
unzipped=`basename "${zipped}" ".gz"`
echo "${unzipped}"
abc.csv

# 2  
Old 10-01-2010
Still it is not working. Here is my code,

unzipped=`basename "$FILE" ".zip"`
echo "unzipped file is $unzipped"
where $FILE = abc.zip (zip of abc.CSV file)

I am getting unzipped file is abc.
Please help me out. Smilie
# 3  
Old 10-06-2010
My code,
Code:
for file in ${DIR}/*\.zip
	do
	       unzip -oqq $file
	done

But I am executing script from another location and I am getting unzipped file into that location.
Actually I need unzipped file into same location DIR.
Please help me out.
# 4  
Old 10-06-2010
with unzip man page:

Code:
       [-d exdir]
              An optional directory to which to extract files.  By default, all files and subdirectories are recreated in the current directory; the  -d  option
              allows  extraction  in  an arbitrary directory (always assuming one has permission to write to the directory).  This option need not appear at the
              end of the command line; it is also accepted before the zipfile specification (with the normal options), immediately after the zipfile  specifica-
              tion,  or between the file(s) and the -x option.  The option and directory may be concatenated without any white space between them, but note that
              this may cause normal shell behavior to be suppressed.  In particular, ''-d ~'' (tilde) is expanded by Unix C shells into the name of  the  user's
              home directory, but ''-d~'' is treated as a literal subdirectory ''~'' of the current directory.

Try:

Code:
for file in ${DIR}/*\.zip
	do
	       unzip -d $DIR -oqq $file
	done

# 5  
Old 10-06-2010
Thanks a lot. Its working fine Smilie

---------- Post updated at 04:51 AM ---------- Previous update was at 04:47 AM ----------

Also tell me the command for .gz type of file, to do the same as mentioned above.
# 6  
Old 10-06-2010
normally, gunzip put the extracted files in the same directory where files are present.
so your files should be in $DIR already.
please try.
# 7  
Old 10-06-2010
using gunzip I am getting only the name of the file, but not the extension.
I want extention as .CSV after gunzip.
Code:
gunzip $file

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