Comparing two files with datestamp to current date


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Comparing two files with datestamp to current date
# 1  
Old 12-15-2011
Comparing two files with datestamp to current date

Hi,
I am new to unix and I am stuck on how to compare two .zip file with date stamp in my directory. I need to compare out of the two file which is oldest to current date and unzip it after that done continue to unzip the second zip file.

Thanks for your help.
# 2  
Old 12-15-2011
This should work:
Code:
ls -rt *.zip | xargs unzip

This User Gave Thanks to bartus11 For This Post:
# 3  
Old 12-15-2011
Bartus11,
Thanks for the reply.

I have a two file ghx_temp_20111214.zip and ghx_temp_20111215.zip. Date changes depending on data delay. So in order for me to unzip it. I would be compairing the date stamp with today date. If the file is older than today date than unzip that first and start a execute process.

Is there a way to to put it in a for loop to loop through the file than check the date with a if statement to begin the process??
# 4  
Old 12-15-2011
You don't have to compare them with today's date. It is enough to compare two of them with one another. If the timestamp is the only variable part of the filename, then simple "ls" will output files sorted alphabetically, which in turn gives the older file first. Try this then:
Code:
ls *.zip | xargs unzip

# 5  
Old 12-15-2011
Is "the date stamp" the one in the name of the file or the one in the unix directory entry?
# 6  
Old 12-15-2011
There are lots of ways to deal with this. As always, you'll get a better answer if you give better info (like, methyl's question could be crucial). You also didn't say what OS you're usuing. Here's a potential way that could get you started. It deals with the zip files based on their mtime (and ignores the "datestamp" in the filename).

Code:
#!/bin/bash
for file in $(ls -tr ghx*zip); do
   unzip -d "$file/" "$file"
   YOUR_PROCESS "$file/extracted_file"
   rm -r "$file/"
   mv "$file" SOME_ARCHIVE_DIR/
done

PS: All the quotes are not necessary if your zips are really always named as your examples, with no spaces.
PPS: Look at the ls man page to understand exactly what's happening. And the unzip one as well, if you need to.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to replace a parameter(variable) date value inside a text files daily with current date?

Hello All, we what we call a parameter file (.txt) where my application read dynamic values when the job is triggered, one of such values are below: abc.txt ------------------ line1 line2 line3 $$EDWS_DATE_INSERT=08-27-2019 line4 $$EDWS_PREV_DATE_INSERT=08-26-2019 I am trying to... (1 Reply)
Discussion started by: pradeepp
1 Replies

2. UNIX for Beginners Questions & Answers

UNIX script to replace old date with current date dynamically in multiple files present in a folder

I am trying to work on a script where it is a *(star) delimited file has a multiple lines starts with RTG and 3rd column=TD8 I want to substring the date part and I want to replace with currentdate minus 15 days. Here is an example. iam using AIX server $ cat temp.txt RTG*888*TD8*20180201~... (1 Reply)
Discussion started by: Shankar455
1 Replies

3. Shell Programming and Scripting

Comparing the dates with the current date in perl scripting

Hi i have a file containg dates likebelow 4/30/2013 3/31/2013 4/30/2013 4/16/2013 4/30/2013 4/30/2013 5/30/2013 5/30/2013 4/30/2013 5/30/2013 5/30/2013 3/31/2013 now i want to compare the above dates with current date and i want to display the difference . (10 Replies)
Discussion started by: siva kumar
10 Replies

4. Debian

Search files that start with current date

hi all, i need to find same files in my directory that looks like this format 20121017145949639.xml (YYYYMMDD*.xml) thanks for help (3 Replies)
Discussion started by: merouan
3 Replies

5. Shell Programming and Scripting

how to copy current date files to another dir

i have directory /abcd and i want to copy all today date files in /xyz directory. i am able to see the files by using below command but not able to understand copy. find . -mtime -1 -type f -exec ls -l {} \; (2 Replies)
Discussion started by: learnbash
2 Replies

6. UNIX for Dummies Questions & Answers

Comparing Output Date to Current System Date

Hi Guys, Anyone who knows how to compare the current date with the a file containing a date, say for example I have a file that looks like this: Command was launched from partition 0. ------------------------------------------------ Executing command in server server6 Fri Dec 16... (7 Replies)
Discussion started by: rymnd_12345
7 Replies

7. Shell Programming and Scripting

Comparing current date

Hi, I have start date and end date in the following format. I need to check the current date is greater than the start date and less than the end date. if i use the command date --date "Tue 6:00 AM", it takes next Tues day not the current week's Tues day. Is there a way to get the current Tues... (9 Replies)
Discussion started by: bharathappriyan
9 Replies

8. Shell Programming and Scripting

Renaming of multiple files with current date

Hi, I have a fixed 4 files in each different directory. The total 17 directories are there each one having 4 files inside it. I need rename all of them with current date. The files formates will be as below: Folder1: abc_NOR_xyz_ddmmyyyy.txt abc_NOR_ghij_ddmmyyyy.txt Folder2:... (5 Replies)
Discussion started by: rjanardhan83
5 Replies

9. Shell Programming and Scripting

Perl: Extracting date from file name and comparing with current date

I need to extract the date part from the file name (20080221 in this ex) and compare it with the current date and delete it, if it is a past date. $file = exp_ABCD4_T-2584780_upto_20080221.dmp.Z really appreciate any help. thanks mkneni (4 Replies)
Discussion started by: MKNENI
4 Replies

10. UNIX for Dummies Questions & Answers

how to find files less than the current date

Hai, i have one directory contains 100 files .each file name like xvb_dateformat.i want find which file names are xvb_lessthan or equal to currentdate. any one give the solution. regards (4 Replies)
Discussion started by: mallikarjuna
4 Replies
Login or Register to Ask a Question