Create multiple zip files each containing 50 xml files.
Hi,
Is there a direct command or need to write a shell script for following requirement?
Everyday a folder is populated with approx 25k to 30k xml files. I need to create multiple zip files in the same folder each containing 50 xml files. The last zip file may or may not contain 50 xml files. Delete all the xml files once the zip files are created successfully.
Example :
If the folder has total of 156 xml files, then I need to create 4 zip files in same folder:
<date>01.zip (containing 50 xml files)
<date>02.zip (containint 50 xml files)
<date>03.zip (containing 50 xml files) and
<date>04.zip (containgin 6 xml files)
-- 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
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:
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)
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)
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)
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)
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)
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)
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)
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)
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)