Files manipulation with time comparison


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Files manipulation with time comparison
# 1  
Old 08-25-2008
Files manipulation with time comparison

Hi guys - I am new to Unix and learning some basics. I have to create a report of files that are in a specific directory and I have to list filenames with specific titles. This report will be created everyday early in the morning, say at 05:00 AM. (see output file format below)

The 2 categories are determined by a particular timestamp 10:30 PM [in HH24:MI:SS format 22:30:00] for the previous day. If the file is recevied before this time, we have to process it, otherwise not process it. See below

Input file
Aug 25 13:10 123.ABC.183.20080825120109.in,BHILA
Aug 25 14:14 234.ABC.456.20080825140016.in,BILA
Aug 25 17:34 345.ABC.338.20080825103713.in,AMDBD
Aug 25 17:39 456.ABC.135.20080825142521.in,HYTU
Aug 25 18:05 678.ABC.139.20080825145020.in,QTRE
Aug 25 20:10 789.ABC.830.20080825120109.in,MHTN
Aug 25 22:14 890.ABC.169.20080825140016.in,KRORA
Aug 25 22:34 901.ABC.388.20080825103713.in,JKLGU
Aug 25 22:39 134.ABC.170.20080825142521.in,DELHR
Aug 25 23:05 256.ABC.171.20080825145020.in,YUTJO
Aug 26 01:05 256.ABC.173.20080825145020.in,YGHJO

Output file
Files to be processed
Aug 25 13:10 123.ABC.183.20080825120109.in,BHILA
Aug 25 14:14 234.ABC.456.20080825140016.in,BILA
Aug 25 17:34 345.ABC.338.20080825103713.in,AMDBD
Aug 25 17:39 456.ABC.135.20080825142521.in,HYTU
Aug 25 18:05 678.ABC.139.20080825145020.in,QTRE
Aug 25 20:10 789.ABC.830.20080825120109.in,MHTN
Aug 25 22:14 890.ABC.169.20080825140016.in,KRORA

Files not to be processed
Aug 25 22:34 901.ABC.388.20080825103713.in,JKLGU
Aug 25 22:39 134.ABC.170.20080825142521.in,DELHR
Aug 25 23:05 256.ABC.171.20080825145020.in,YUTJO
Aug 26 01:05 256.ABC.173.20080825145020.in,YGHJO


Appreciate some guidance regarding this.
# 2  
Old 08-25-2008
You didn't show your effort to solve your problem:
Search this forum for:
a. How to calculate yesterday date (man date)
b. How to regexp from time to time(awk, sed, etc..)

Success,
# 3  
Old 08-25-2008
awk '{if($3<"22:30" && $2 <"26") print $0 > "processed.txt"; else print $0 > "nottoprocess.txt";}' inputfile
Just a temporary solution. Actually u need to work on date comparison.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

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

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

3. Shell Programming and Scripting

Time Manipulation in shell script

Hi all, I have a script that requires time comparisons and sending out an email alert only if the specified interval has been completed. The script runs in Cron tab every 5 mins. For ex: If the interval is set to 2 hrs (Dynamic & varies ) My script should execute and if it finds any error... (1 Reply)
Discussion started by: praseecg
1 Replies

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

5. Shell Programming and Scripting

Time comparison

hi friends, I am new to shell scripting and i am using KSH shell .I would like to automate our daily routine manual tasks .first i ll explain the situation .I will list out the contents of directory named "log" using "ls " and verify whether all the listed files time differences is... (3 Replies)
Discussion started by: rdhaprakasam
3 Replies

6. Shell Programming and Scripting

need help in time manipulation

i have a script that gives the last time the data is inserted in a file. i want to check the time difference b/w the sytem time and the time in file. for e,g. if script runs at 3.30.So $a=3.30 and the time in file is 3.00.So $time =3.00 then the time difference should be 30 min...... ... (6 Replies)
Discussion started by: ali560045
6 Replies

7. Shell Programming and Scripting

Help with time comparison shell script for HP-UX

I am using Korne Shell in HP-Ux. Can someone give me and idea on how I can write a shellscript on how to do this please:- On our HP-UX server, a batch file is run every evening at about 6:30pm. The first step of this batch file will touch an empty "flag" file to indicate that the batch has... (6 Replies)
Discussion started by: gummysweets
6 Replies

8. Shell Programming and Scripting

Newbee Needs Help - Time comparison

I am very new to Unix so please bear with me! I am trying to write a script that will compare file creation time with the current time so I can be notified if a file is more than an hour old. Can anybody point me in the right direction on this??? Thank you in advance for any help!!! It is GREATLY... (4 Replies)
Discussion started by: danedder
4 Replies

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

10. Programming

Time/date manipulation

hey folks, been awhile (actaully a long while) since i last touched C. And the 3 books i've read don't really have much about using time.h Question: How would i be able to assign a variable the value of the current date minus 2 mths, keeping in mind the yr. IE. would like to see Nov.31/2001... (1 Reply)
Discussion started by: choice
1 Replies
Login or Register to Ask a Question