Specific file list to be zip


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Specific file list to be zip
# 1  
Old 02-28-2011
Specific file list to be zip

Hi,

I need a specific list of files to be zip automatically. based on the criteria

Criteria:
1. It should not be the current file and not less than 10 files
e.g in a folder contails 100 files
jan 50 -> contains ->45 zip files e.g. XXX.gz 5 normal log files e.g XXX.log
feb 50 -> contains -> 45 normal log files e.g. XXX.log

my output should be it should zip the remaining five jan *.log files and feb first five *.log files should zip.

ultimately it should not zip the current log file and 20 old log files. because all log files are rotating. we need it for verification. please help me ASAP.

thanks. let me know if you have any questions.

---------- Post updated at 04:10 AM ---------- Previous update was at 04:10 AM ----------

need a immediate solutions very urgent
# 2  
Old 02-28-2011
Everyone at the UNIX and Linux Forums gives their best effort to reply to all questions in a timely manner. For this reason, posting questions with subjects like "Urgent!" or "Emergency" and demanding a fast reply are not permitted in the regular forums.

For members who want a higher visibility to their questions, we suggest you post in the Emergency UNIX and Linux Support Forum. This forum is given a higher priority than our regular forums.

Posting a new question in the Emergency UNIX and Linux Support Forum requires forum Bits. We monitor this forum to help people with emergencies, but we do not not guarantee response time or best answers. However, we will treat your post with a higher priority and give our best efforts to help you.

---------- Post updated at 10:24 ---------- Previous update was at 10:21 ----------

I can't really make heads or tails from your description. How is the current file determined? On what criteria are the files selected? Time? A pattern in the file name? What kind of system are you on (and don't say UNIX now, we need the specific version and/or distribution)?
# 3  
Old 02-28-2011
Thanks for your prompt response here is my answers to your questions :

1. I am using Linux 2.6.31-14-generic #48-Ubuntu SMP GNU/Linux
2.
Code:
-rw-r--r-- 1 root root        46 2011-01-25 20:24 ab_xxxxxx.log.201101252024.gz
-rw-r--r-- 1 root root        46 2011-01-26 19:10 ab_xxxxxx.log.201101261910.gz
-rw-r--r-- 1 root root         0 2011-01-29 21:41 ab_xxxxxx.log.201102281726
-rw-r--r-- 1 root root         0 2011-01-30 18:54 ab_xxxxxx.log.201101301854
-rw-r--r-- 1 root root         0 2011-01-31 18:58 ab_xxxxxx.log.201101311858
-rw-r--r-- 1 root root         0 2011-02-01 15:14 ab_xxxxxx.log.201102201514
-rw-r--r-- 1 root root         0 2011-02-02 15:48 ab_xxxxxx.log.201102211548
-rw-r--r-- 1 root root         0 2011-02-03 15:42 ab_xxxxxx.log.201102221542
-rw-r--r-- 1 root root         0 2011-02-04 15:42 ab_xxxxxx.log.201102221542
-rw-r--r-- 1 root root         0 2011-02-05 15:42 ab_xxxxxx.log.201102221542
-rw-r--r-- 1 root root         0 2011-02-06 15:42 ab_xxxxxx.log.201102221542
-rw-r--r-- 1 root root         0 2011-02-07 15:42 ab_xxxxxx.log.201102221542
-rw-r--r-- 1 root root         0 2011-02-08 15:42 ab_xxxxxx.log.201102221542
.
.
.
.
..

-rw-r--r-- 1 root root         0 2011-02-18 15:42 ab_xxxxxx.log.201102221542
-rw-r--r-- 1 root root         0 2011-02-19 15:42 ab_xxxxxx.log.201102221542
.
.
.
-rw-r--r-- 1 root root         0 2011-02-27 15:42 ab_xxxxxx.log.201102221542
-rw-r--r-- 1 root root         0 2011-02-28 15:00 ab_xxxxxx.log

Marking bold letters only I need such has only five files to be zipped automatically. similarly it should follow the same condition for next five files to be zipped only if i run the script. please note it should not zip current file ab_xxxxxx.log as well as last 10 days files. let me know if you have any questions and thank you for helping me out.

Last edited by jagkoth; 02-28-2011 at 12:23 PM..
# 4  
Old 02-28-2011
OK, one attempt to rephrase that: you want to compress (not zip, the ZIP format is an archive format) all files not already compressed that are at least 10 days old?
# 5  
Old 02-28-2011
the log name format is good.

Code:
ls -r ct_agent.log.20*|grep -v gz |sed -n '11,$p' |xargs gzip

This User Gave Thanks to rdcwayx For This Post:
# 6  
Old 02-28-2011
not all the files only that specific files to be zip. say for e.g. If i zip that 5 files next time if i ran the script it will zip the next five files

---------- Post updated at 05:05 AM ---------- Previous update was at 04:54 AM ----------

rdcwyx - First time it works. If I run the same command next time its not compressing the next 5 files. please see the error:

Code:
# ls -r ab_xxxxxx.20*|grep -v gz |sed -n '11,$p' |xargs gzip
gzip: compressed data not written to a terminal. Use -f to force compression.
For help, type: gzip -h


Last edited by jagkoth; 02-28-2011 at 12:24 PM.. Reason: please use code tags
# 7  
Old 02-28-2011
Why only 5 at a time, and what is the selection criteria in terms a computer could understand? Should it be always a maximum of 5 at a time, or is there another criteria that could make it less or more files?
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

Uncompressing .zip file specific directory Fedora 14

Hello, I have Fedora 14 installed on my machine I have a .zip file ( some latex package) which I want to unzip to some location in the Latex paths /usr/share.../texmf/.. so I went to super user mode, created the directory for this package over there, mkdir logo and tried... (1 Reply)
Discussion started by: ajayram
1 Replies

4. Shell Programming and Scripting

Find all the files under a specific directory and zip them into a single file.

Hi, Is there a way to find all the files from a specific location and then zip them into a single file, even if they are in multiple directories? (3 Replies)
Discussion started by: rudoraj
3 Replies

5. Shell Programming and Scripting

Zip a list of specific files to an archive

Hi all, i've got the following problem: We've got a shell-script, that creates some different files based on several criteria given, using a sql-script. After creating, those files are individually zipped and stored, then sent to a ftp-server. This is all working since 2010, but now they have... (3 Replies)
Discussion started by: Biggreuda
3 Replies

6. UNIX for Dummies Questions & Answers

Zip file with specific name

Hi, How could compress a file with a specific name. For example if I put the following: gzip -f file.dat I compressed it with the same file name to compress, "file.dat.gz". How could compress it with the name I want for example test.gz. Thanks. (4 Replies)
Discussion started by: pepeli30
4 Replies

7. Shell Programming and Scripting

Matching a string (zip code) from a list in a separate file

I have a list of postal addresses and I need to pull the records that match a list of zip codes in a separate file. The postal addresses are fixed width. The zip code is located in character position 149-157. Something better than: cat postalfile.txt | grep -f zipcodes.txt would be great. $... (8 Replies)
Discussion started by: sitney
8 Replies

8. Shell Programming and Scripting

Read specific file from a zip archive without extracting

Hi All, I would like to extract specific file from a zip archive. I have a zip archive "sample.zip". sample.zip contains few text files and images... text1.txt, text2.txt, pic.jpg etc... I need to read specific file "text2.txt" from "sample.zip" WITHOUT EXTRACTING the zip file. ... (4 Replies)
Discussion started by: sridharg
4 Replies

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

10. UNIX for Dummies Questions & Answers

Is extracting specific files from a zip file possible?

If a zip file contains several zip files, but if the file names of the files needed are known, is there a variation of the unzip command that will allow those few (individual) files to be extracted? --- Example: Zip file name: zip.zip unzip -l zip.zip will display file01, file02, file03, etc.... (1 Reply)
Discussion started by: HLee1981
1 Replies
Login or Register to Ask a Question