Zip the file in a loop in ksh 88


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Zip the file in a loop in ksh 88
# 1  
Old 09-10-2013
Zip the file in a loop in ksh 88

Hi Team,

Version : Ksh 88

The Requirement is to zip every file in a folder(which is in for loop) and move the zipped file to another folder
I tried like the below , but didn't observe any change ( Infact more size ) after the file is zipped .
Code:
#!/bin/ksh
 
src_dir=/home/etc/Src_dat
dest_dir=/home/etc/zipped_dat
for test_file in `ls $src_dir`
 do
   cd $src_dir
   zip "$test_file.zip" "$test_file"
    mv $src_dir/$test_file.zip $dest_dir
done

With the code like above , I observe that
In the source folder the size of the file was 158 Data_day1.txt
In the destination folder the size of the file is 273 Data_day1.txt
Please advice where is the wrong in the above code !!!

Thank You
# 2  
Old 09-10-2013
Might be due to headers
# 3  
Old 09-10-2013
Thank You for the reply Rakesh,

I'm sorry , I didn't understand about headers


Thanks
# 4  
Old 09-10-2013
# 5  
Old 09-10-2013
Thank You for the information Rakesh,

Can you please suggest me any change in the script so that it zip the every file correctly .
Or Is this fine ..

Thanks,
# 6  
Old 09-10-2013
if you want to see the size difference with Zip, please try with a bigger file like say 1MB.

Before Zip
Code:
rakesh@xyz:/tmp/zlinux> du cics_log_01-09-12-22\:56\:00.tar.gz
4       cics_log_01-09-12-22:56:00.tar.gz

After zip , its size is increased due to zip headers
Code:
rakesh@xyz:/tmp/zlinux> ls -l cics_log_01-09-12-22\:56\:00.tar.gz*
-rw-r--r-- 1 rakesh users  45 2013-09-10 06:13 cics_log_01-09-12-22:56:00.tar.gz
-rw-r--r-- 1 rakesh users 239 2013-09-10 06:14 cics_log_01-09-12-22:56:00.tar.gz.zip

---------- Post updated at 06:21 AM ---------- Previous update was at 06:20 AM ----------

your method is correct and you can go ahead, but you can test it with unzip just to make sure its doesn't loose integrity
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How can we Zip multiple files created on the same date into one single zip file.?

Hi all i am very new to shell scripting and need some help from you to learn 1)i have some log files that gets generated on daily basis example: i have abc_2017_01_30_1.log ,2017_01_30_2.log like wise so i want to zip this 4 logs which are created on same date into one zip folder. 2)Post zipping... (1 Reply)
Discussion started by: b.saipriyanka
1 Replies

2. UNIX for Beginners Questions & Answers

How can we Zip multiple files created on the same date into one single zip file.?

Hi all i am very new to shell scripting and need some help from you to learn 1)i have some log files that gets generated on daily basis example: i have abc_2017_01_30_1.log ,2017_01_30_2.log like wise so i want to zip this 4 logs which are created on same date into one zip folder. 2)Post zipping... (2 Replies)
Discussion started by: b.saipriyanka
2 Replies

3. Shell Programming and Scripting

ksh Loop through file one, remove lines from file two

Good Afternoon, I start with a file named biglist.txt. I have another file smallerlist. txt I want to remove the lines from smallerlist.txt from biglist.txt and leave those lines that do not reside in smallerlist.txt. Thanks !! (2 Replies)
Discussion started by: popeye
2 Replies

4. Shell Programming and Scripting

Loop through the dir and Rename zip files and their underlying text file.

I have files in the ABC_YYYYMMDD.zip format under a directory. Each zip file contains A text file in the ABC_YYYYMMDD.txt format. I am trying to create a script that will Rename the zip files and their underlying text file replacing the datepart in them with . For eg: in the case of... (1 Reply)
Discussion started by: bash987
1 Replies

5. Shell Programming and Scripting

Zip Multiple files to One .zip file in AIX system

Hi I have a requirement in unix shell where I need to zip multiple files on server to one single .zip file. I dont see zip command in AIX and gzip command not doing completely what I want. One I do .zip file, I should be able to unzip in my local Computer. Here is example what I want... (9 Replies)
Discussion started by: RAMA PULI
9 Replies

6. Shell Programming and Scripting

Passinng specific file extension to while loop in ksh

hello, i have the below while loop wherein i am passig list of filenames to be scped. this is in unix ksh - filenamelist.txt has list of files names, including .dat and .txt files but i want to pass only the .txt filenames to the while loop so that only .txt files gets scped. how can... (4 Replies)
Discussion started by: billpeter3010
4 Replies

7. UNIX for Advanced & Expert Users

Zip file inside Zip file(s)

I've a zip file called Z00.zip and in that file there are 22 more zip files. Each zip file having .txt files nearly 10,000 files. I am trying to unzip all these .txt files in one command line to unzip each .zip file from Z00.zip file. Would like to know whether possible to unzip all sub-zip files... (1 Reply)
Discussion started by: nvkuriseti
1 Replies

8. UNIX for Dummies Questions & Answers

Zip a file with .zip extension.

Hi, I need to zip a .dat file with .zip extension. I tried using the "zip" command. But shell says. "ksh: zip: not found" Currently I am using gunzip to zip and changing the extension ".gz" to ".zip" as follows. mv $file `echo $file | sed 's/\(.*\.\)gz/\1zip/'` But when I tried... (1 Reply)
Discussion started by: aeroticman
1 Replies

9. AIX

ZIP multiple files and also specify size of zip file

I have to zip many pdf files and the size of zip file must not exceed 200 MB. When size is more than 200 MB then multiple zip files needs to be created. How we can achieve this in UNIX? I have tried ZIP utility but it takes a lot of time when we add individual pdfs by looping through a... (1 Reply)
Discussion started by: tom007
1 Replies

10. UNIX for Dummies Questions & Answers

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... (5 Replies)
Discussion started by: oracledev
5 Replies
Login or Register to Ask a Question