Date comparison in file to system time


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Date comparison in file to system time
# 1  
Old 03-04-2009
Date comparison in file to system time

I have a CSV (comma separated vaule) file whose entries resemble

Code:
Area,\\ntsvsp02\vmcs\download\files\Areas.dat,1,20090303,0,Import Complete,2009-03-02 04:23:00
Product,\\ntsvsp02\vmcs\download\files\items.dat,1,20090303,0,Import Complete,2009-03-02 04:23:00
Store,\\ntsvsp02\vmcs\download\files\Stores.dat,1,20090303,0,Import Complete,2009-03-02 04:25:00
Region,\\ntsvsp02\vmcs\download\files\Regions.dat,1,20090303,0,Import Complete,2009-03-02 04:25:00
LineList,\\ntsvsp02\vmcs\download\files\linelist.dat,1,20090301,0,Import Complete,2009-03-01 06:27:00

Code:
RangingDates,1,20090302,20090303,17,0,Export Complete,2009-03-01 19:54:00
FutureModuleList,1,20090302,20090303,6,0,Export Complete,2009-03-01 06:00:00
StoreDescription,1,20090303,20090304,5,0,Export Complete,2009-03-02 05:00:00
StoreToDisplay,1,20090303,20090304,5,0,Export Complete,2009-03-02 05:18:00
FutureStoreToDisplay,1,20090302,20090303,6,0,Export Complete,2009-03-01 06:05:00
FutureStoreDescription,1,20090302,20090303,6,0,Export Complete,2009-03-01 06:06:00
Module,1,20090302,20090303,15,0,Export Complete,2009-03-01 15:00:00
ModuleDispOpt,1,20090302,20090303,15,0,Export Complete,2009-03-01 15:01:00
DispOptProduct,1,20090302,20090303,14,0,Export Complete,2009-03-01 15:10:00
StoreDispOpt,1,20090302,20090303,15,0,Export Complete,2009-03-01 15:13:00
StoreItem,1,20090302,20090303,13,0,Export Complete,2009-03-01 14:06:00


I need to a command (I think awk could be helpful?) which will scan the last column (i.e. the date and time) and set a variable called TIME_EXCEEDED to one (1) i.e. TIME_EXCEEDED=1 if the if they (any one of the last column entry) are older than 24 hours (when being compared to the system time).

Please let me know if the above information was helpful
# 2  
Old 03-05-2009
Date comparison in file to system time

Could kindly advise if had a chance to look at this.
# 3  
Old 03-05-2009
One way is :

Code:
YESTERDAY=`perl -e '@T=localtime(time-'86400');printf("%02d-%02d-%02d %02d:%02d:%02d ",($T[5]+1900,$T[4]+1,$T[3],$T[2],$T[1],$T[0]))'

`

Then use this YESTERDAY variable as using -v in nawk e.g.

Code:
TIME_EXCEEDED=`nawk -F, -v YEST="$YESTERDAY" ' BEGIN {OK="0"} { if ( $NF < YEST ) OK="1"  } END { print OK } ' FILENAME `

# 4  
Old 03-06-2009
pnm

Thanks a lot for the solution. It is working Smilie.

Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. SCO

Cannot use 'date -t' to set the system date and time

Hi! All, I am trying to reset the date and time since the change in time over the weekend. I cannot issue the command date -t 201703131330. The system gives me an error invalid option. This happens on my SCO OpenServer 5.0.7 and 5.0.6. Do anyone have an idea why? I even tried using... (6 Replies)
Discussion started by: trolley
6 Replies

2. Shell Programming and Scripting

[Solved] How to tar data along with current system date and time.?

Hi all, Following is my small script:- #!/bin/ksh for i in `cat /users/jack/mainfile-dr.txt` do sudo cp -r $i /users/jack/DR01/. done cd /users/jack/DR01/ sudo tar cvf system1-DR.tar * scp system1-DR.tar backupserver:/DRFiles/system1 sudo rm -rf system1-DR.tar In this script I... (10 Replies)
Discussion started by: manalisharmabe
10 Replies

3. Shell Programming and Scripting

Date and Time comparison using shell script

Hi, I'm having two fields in the file F1|F2 20111220|102000 F1 ->YYYYMMDD F2 ->HHMMSS Now, I need to compare this with current date & time and need to return the difference value in hours. Already, I checked with datecalc from the forum. So, need hints from Shell Gurus. Thanks (10 Replies)
Discussion started by: buzzusa
10 Replies

4. Shell Programming and Scripting

append a filename with system date and time

Hi, There are similar kind of posts, but none seems like working for me. Please correct me if I'm wrong. I need append/rename file abc.txt with file processed date and time like abc_systemdatetimestamp.txt and move it to different folder. for example I have /source/data/abc.txt ... (1 Reply)
Discussion started by: amsn08
1 Replies

5. Shell Programming and Scripting

File modification time comparison

Hi All, I have two files (given below) each exists under different paths. I want to compare the modification time stamp of file1.txt is lessthan the modification time of file2.txt. month1=`ls -l file1.txt | awk '{ print $6}'` date1=`ls -file1.txt | awk '{ print $7}'` time1=`ls... (1 Reply)
Discussion started by: Arunprasad
1 Replies

6. Homework & Coursework Questions

Date comparison with 'string date having slashes and time zone' in Bash only

1. The problem statement, all variables and given/known data: I have standard web server log file. It contains different columns (like IP address, request result code, request type etc) including a date column with the format . I have developed a log analysis command line utility that displays... (1 Reply)
Discussion started by: TariqYousaf
1 Replies

7. Shell Programming and Scripting

Removing rows from a file based on date comparison

I have a '|' delimited file and want to remove all the records from the file if the date is greater than a year from sysdate. The layout of the file is as below - xxxxxxxxxxxxxx|yyyyyy|zzzzzz|2009-12-27-00:00| 000000000|N xxxxxxxxxxxxxx|yyyyyy|zzzzzz|2010-01-03-00:00| 000000000|N... (4 Replies)
Discussion started by: Max_2503
4 Replies

8. Shell Programming and Scripting

System time comparison to fixed defined time

I have a requirement of checking the current system time and performing certain actions in a shell script. example: if the current system time is greater than 1400 hrs, then perform step 1,2,3 if the current system time is greater than 1000 hrs, then perform step 1,2 if the current system time... (2 Replies)
Discussion started by: zainravi
2 Replies

9. Shell Programming and Scripting

Processing a log file based on date/time input and the date/time on the log file

Hi, I'm trying to accomplish the following and would like some suggestions or possible bash script examples that may work I have a directory that has a list of log files that's periodically dumped from a script that is crontab that are rotated 4 generations. There will be a time stamp that is... (4 Replies)
Discussion started by: primp
4 Replies

10. UNIX for Advanced & Expert Users

File Time Comparison Question

I want a cron job to fire off every 5 minutes or so to verify that a file in a directory is not more than 15 minutes old (from the current time. If the newest file is more than 15 minutes old, I would fire off an email.. The email part is easy, but I'm having trouble figuring the logic... (2 Replies)
Discussion started by: pc9456
2 Replies
Login or Register to Ask a Question