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:

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

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.

Dummytest_20140601W110515_file001.txt
Dummytest_20140601W110515_file002.txt
Dummytest_20140601W110515_file003.txt

Thanks

Thanks for the information, but that didn't answer all the questions. If in addition to having the files:

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:

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?

Maybe something like this:

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

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

All file with *.txt will be zipped. The above mentioned solution works perfectly fine.

Thanks