Grabing the same timestamp from files that are ZIPPED


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Grabing the same timestamp from files that are ZIPPED
# 1  
Old 07-25-2014
Grabing the same timestamp from files that are ZIPPED

Hi,

I am zipping more than 20 files that has same timestamp in all of them. I need to create the zip file with the same timestamp as in the files that are zipped.

So I have files:
Code:
Dummytest_20140601W110515_file1.txt
Dummytest_20140601W110515_file2.txt
.......
.......
Dummytest_20140601W110515_file20.txt
......

The first one in bold above is the date =20140601
The first second one in bold above is the time upto seconds =110515

All I am trying to get is the zip the above files with the same timestamp as in the files. Something like: APP_Deg_Dummy_20140601TM110515_File.zip. The date and time needs to be same as in the file.

I tried the code below: But the timestamp is different in the Zip file. I need the timestamp to be same as in the files.
Also, we are not using gzip at all.

zip APP_Deg_Dummy_`date +%Y%m%d`TM`date +%H%M%S`_File.zip *.txt


Will appreciate your advice.

Thanks
Moderator's Comments:
Mod Comment Please use code tags for sample input, output, AND code segments.

Last edited by Don Cragun; 07-25-2014 at 03:05 PM.. Reason: Add missing CODE tags.
# 2  
Old 07-25-2014
How will the list of files be given to your script? Do you have a pattern that is used to select the files to be zipped, or do you have a file that contains the list of files to be zipped?

Is your script supposed to search a directory for sets of files with the same timestamp and zip each set?

Should we assume that you're using a Solaris system for this problem as in some of your earlier threads?

And what shell are you using?

Last edited by Don Cragun; 07-25-2014 at 03:07 PM.. Reason: Add request for shell information.
# 3  
Old 07-25-2014
Quote:
Originally Posted by Don Cragun
How will the list of files be given to your script? Do you have a pattern that is used to select the files to be zipped, or do you have a file that contains the list of files to be zipped?

Is your script supposed to search a directory for sets of files with the same timestamp and zip each set?

Should we assume that you're using a Solaris system for this problem as in some of your earlier threads?

And what shell are you using?
Thanks for the response. I just need to zip certain txt files in a one particular directory and do not have to do any search or zip the files in the subdirectories at all. The files are generated by some other process in a given directory. I just have to zip them. Filenames are given below.
I am using Solaris and Ksh shell.

So I have a directory DIR, say DIR1. Lets say there are three files with the same date and time in the DIR1 directory(please see below the filenames). I need to zip the three files (shown below). ALL Files will have same date and time in them as shown below. The zip file needs to have the date and time same as in the files getting zip.

Code:
Dummytest_20140601W110515_file001.txt
Dummytest_20140601W110515_file002.txt
Dummytest_20140601W110515_file003.txt

Thanks

Last edited by Don Cragun; 07-25-2014 at 04:28 PM.. Reason: Change ICODE tags to CODE tags.
# 4  
Old 07-25-2014
Thanks for the information, but that didn't answer all the questions. If in addition to having the files:
Code:
Dummytest_20140601W110515_file001.txt
Dummytest_20140601W110515_file002.txt
Dummytest_20140601W110515_file003.txt

in a directory, the same directory contains another set of files, perhaps something like:
Code:
Dummytest_20140603W214545_file001.txt
Dummytest_20140603W214545_file002.txt
Dummytest_20140603W214545_file004.txt
Dummytest_20140603W214545_file005.txt
Dummytest_20140603W214545_file006.txt

how will you tell your script which set to zip? Or will this never happen? If it could happen, should both sets be zipped.

Will there ever be any files in the directory containing these files with names ending with .txt that should not be zipped.

Will the zip file always be named APP_Deg_Dummy_dateTMtimestamp_File.zip? If not, how will the various parts of the name to be used for a given invocation be passed to your script?
# 5  
Old 07-25-2014
Maybe something like this:

Code:
zip APP_Deg_Dummy_$(ls | head -n1 | awk -F_ '{print substr($2, 1, 8)"TM"substr($2, 10, 6)}').zip Dummytest_20140601W110515_file*
  adding: Dummytest_20140601W110515_file1.txt (stored 0%)
  adding: Dummytest_20140601W110515_file2.txt (stored 0%)

ls *.zip
APP_Deg_Dummy_20140601TM110515.zip

This User Gave Thanks to in2nix4life For This Post:
# 6  
Old 07-28-2014
Quote:
Originally Posted by in2nix4life
Maybe something like this:

Code:
zip APP_Deg_Dummy_$(ls | head -n1 | awk -F_ '{print substr($2, 1, 8)"TM"substr($2, 10, 6)}').zip Dummytest_20140601W110515_file*
  adding: Dummytest_20140601W110515_file1.txt (stored 0%)
  adding: Dummytest_20140601W110515_file2.txt (stored 0%)

ls *.zip
APP_Deg_Dummy_20140601TM110515.zip

Thanks a ton. This is working fine and as expected.

All the files in the given directory are zipping fine.

Thanks...This is very helpful.

---------- Post updated at 11:41 AM ---------- Previous update was at 11:39 AM ----------

Quote:
Originally Posted by Don Cragun
Thanks for the information, but that didn't answer all the questions. If in addition to having the files:
Code:
Dummytest_20140601W110515_file001.txt
Dummytest_20140601W110515_file002.txt
Dummytest_20140601W110515_file003.txt

in a directory, the same directory contains another set of files, perhaps something like:
Code:
Dummytest_20140603W214545_file001.txt
Dummytest_20140603W214545_file002.txt
Dummytest_20140603W214545_file004.txt
Dummytest_20140603W214545_file005.txt
Dummytest_20140603W214545_file006.txt

how will you tell your script which set to zip? Or will this never happen? If it could happen, should both sets be zipped.

Will there ever be any files in the directory containing these files with names ending with .txt that should not be zipped.

Will the zip file always be named APP_Deg_Dummy_dateTMtimestamp_File.zip? If not, how will the various parts of the name to be used for a given invocation be passed to your script?
All file with *.txt will be zipped. The above mentioned solution works perfectly fine.

Thanks
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Work with huge Zipped files

Hello dear members, I have one general and one specific question which I will be very grateful if you could help me with them. Let's start with my general question: 1. I am working on cluster computer shared with other people and I need to manipulate a big zipped text file of 13 GB. There is... (1 Reply)
Discussion started by: Homa
1 Replies

2. Shell Programming and Scripting

Renaming all files inside a zipped file

Hi, To all the Unix gurus this should be a simple task, but as a newbie I'm finding it hard to crack this. Any help is highly appreciated... Scenario: Step 1 : Move zip file from FTP folder to WORK folder Step 2: Unzip the file "Sample_YYYYMMDDHHMMSS.tar.gz" which contains many file... (10 Replies)
Discussion started by: asandy1234
10 Replies

3. Shell Programming and Scripting

Identifying files with a timestamp greater than a given timestamp

I need to be able to identify files with file timestamps greater than a given timestamp. I am using the following solution, although it appears to compare files at the "seconds" granularity and I need it at the milliseconds. When I tested my solution, it missed files that had timestamps... (3 Replies)
Discussion started by: nkm0brm
3 Replies

4. Shell Programming and Scripting

Copy all zipped files from one folder to another

Hi everyone, when I try to copy *.gz files run cp within the correct source folder it works as follow: Source folder = C:/Documents and Settings/user/Recent papers/2771/ Destination folder = C:/Documents and Settings/user/My documents/1532/temp cp *.gz "C:/Documents and Settings/user/My... (2 Replies)
Discussion started by: cgkmal
2 Replies

5. Shell Programming and Scripting

Difference between 2 zipped text files.

Hi, I have below two zipped files - file1.gz 023384148,1,,,02077301961,R,02077301961,N,0,02077301961,N,0,0,8010,02077300518,U,N,,02077300518,U,20100501011732,20100501011732,0,20100501011815,00000430,16,16,10,N;... (8 Replies)
Discussion started by: ravigupta2u
8 Replies

6. Linux

grep thru zipped files

Hi All, I need to check the logs and grep it. The problem is that the previous days are zipped with *.gz. How do grep on the *.gz? Thank you in advance. (1 Reply)
Discussion started by: itik
1 Replies

7. Shell Programming and Scripting

Greping from zipped files without unzipping

I have more than 500 gzipped files in a directory. I have one lookup file in the same directory with 200 key values. I need to get the name of the gzipped file which have any of these 200 key values. Here my criteria is do not unzip the files due to space constraint. Any suggestion? (3 Replies)
Discussion started by: kanu_kanu
3 Replies

8. Shell Programming and Scripting

Grabing the username

Hi, Is there a way to grab the username who is running the shell script. I am trying to do is: $ who am i Peterd123 pts/5 Mar 20 09:30 (H0021563.xyz.com) Is there a way to display only the user name above, which is"Peterd123". Thanks Raj (3 Replies)
Discussion started by: rkumar28
3 Replies

9. Shell Programming and Scripting

Grabing a file from a directory

Hi guys: I need to grab a particular file(s) from a directory. the file name is abc.xyz.2006020101200 I need to grab it based on the bold numbers. The bolded numbers are the date and such files are created everyday. My initial script was to grab the listing of that directory and then cut... (1 Reply)
Discussion started by: geomonap
1 Replies

10. UNIX for Dummies Questions & Answers

uploading Zipped files get 553 error

I am trying to upload .zip files to Unix server and get the error 553 qmerev2002.zip: Permission denied, what is my problem?? I am able to load other files and folders fine. (3 Replies)
Discussion started by: CoastGuard1970
3 Replies
Login or Register to Ask a Question