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).
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"?
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` ?
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.
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.
[-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:
for file in ${DIR}/*\.zip
do
unzip -d $DIR -oqq $file
done