Sponsored Content
Top Forums Shell Programming and Scripting Create multiple zip files each containing 50 xml files. Post 302883385 by Rakesh Thobula on Tuesday 14th of January 2014 01:05:28 AM
Old 01-14-2014
Thanks Robin.

-- I tried zip command which worked for all files in the folder.
-- Just a novice in Shell scripting
-- Linux
-- bash

I will be trying to extend my code to include "for" for specific range of files to be zipped.

Rakesh

---------- Post updated at 05:05 PM ---------- Previous update was at 11:29 AM ----------

Finally achieved what I wanted.
Now folder will have only zip files. So one less work - no need of deletion of individual files in folder.

Here is the code :
------------------
Code:
#!/bin/sh
#NOW will hold the date format as : yyyyddmmhhmiss
NOW="$(date +"%Y%m%d%H%M%S")"
#LIMIT the number of files to go in each zip file
LIMIT=2
COUNT=0
#DIR is initialized with initial value 0001 and later in the code it is incremented. While loop is required to put leading zeros to DIR.
DIR=0001
#Start FOR loop for number of xml files in the folder
for FILE in *txt
do
#Add each file to zip with zip filename
zip -r $NOW-$DIR $FILE
let COUNT=$COUNT+1
#If the for loop reaches the Limit, then start putting files into new zip file
if [ $COUNT -eq $LIMIT ]
then
# base 10 ie. 10# is used in the code below to avoid error : value too great for base
let DIR=10#$DIR+1
#WHILE loop is needed to put the leading zeros to the variable DIR
while [ ${#DIR} -ne 4 ];
do
DIR="0"$DIR
done
COUNT=0
fi
done

-----------------

Thanks for supporting me in learning what I should do.

Posting this for the benefit of others.

Thanks
Rakesh Smilie

Last edited by Franklin52; 01-14-2014 at 03:15 AM.. Reason: Please use code tags
This User Gave Thanks to Rakesh Thobula For This Post:
 

9 More Discussions You Might Find Interesting

1. 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

2. UNIX for Dummies Questions & Answers

Zip multiple files and copy to help

Hi All, I have a set of large files ~ 500_900Mb I have generated and I'd like to quickly zip and copy them to a new folder elsewhere ... Can anyone suggest a quicky ?? Cheers :) (3 Replies)
Discussion started by: pawannoel
3 Replies

3. Programming

help need in the perl script that create one xml file form multiple files.

Hi every one, Please excuse me if any grammatical mistakes is there. I have multiple xml files in one directory, I need to create multiple XML files into one XML file.example files like this</p> file1:bvr.xml ... (0 Replies)
Discussion started by: veerubiji
0 Replies

4. 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

5. Shell Programming and Scripting

How to create zip/gz/tar files for if the files are older than particular days in UNIX or Linux?

I need a script file for backup (zip or tar or gz) of old log files in our unix server (causing the space problem). Could you please help me to create the zip or gz files for each log files in current directory and sub-directories also? I found one command which is to create gz file for the... (4 Replies)
Discussion started by: Mallikgm
4 Replies

6. Shell Programming and Scripting

Extract strings from XML files and create a new XML

Hello everybody, I have a double mission with some XML files, which is pretty challenging for my actual beginner UNIX knowledge. I need to extract some strings from multiple XML files and create a new XML file with the searched strings.. The original XML files contain the source code for... (12 Replies)
Discussion started by: milano.churchil
12 Replies

7. Shell Programming and Scripting

Splitting a single xml file into multiple xml files

Hi, I'm having a xml file with multiple xml header. so i want to split the file into multiple files. Sample.xml consists multiple headers so how can we split these multiple headers into multiple files in unix. eg : <?xml version="1.0" encoding="UTF-8"?> <ml:individual... (3 Replies)
Discussion started by: Narendra921631
3 Replies

8. 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

9. 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
ZIPMERGE(1)						      General Commands Manual						       ZIPMERGE(1)

NAME
zipmerge - merge zip archives SYNOPSIS
zipmerge [-DhIiSsV] target-zip source-zip Op source-zip ... DESCRIPTION
zipmerge merges the source zip archives source-zip into the target zip archive target-zip. By default, files in the source zip archives overwrite existing files of the same name in the target zip archive. Supported options: -D Ignore directory components in file name comparisons. -h Display a short help message and exit. -I Ignore case in file name comparisons -i Ask before overwriting files. See also -s. -S Do not overwrite files that have the same size and CRC32 in both the source and target archives. -s When -i is given, do not before overwriting files that have the same size and CRC32. -V Display version information and exit. EXIT STATUS
zipmerge exits 0 on success and 1 if an error occurred. SEE ALSO
zipcmp(1), ziptorrent(1), libzip(3) AUTHORS
Dieter Baron <dillo@giga.or.at> and Thomas Klausner <tk@giga.or.at> NiH June 4, 2008 ZIPMERGE(1)
All times are GMT -4. The time now is 07:03 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy