Updating a File


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Updating a File
# 1  
Old 07-10-2014
Updating a File

Hi,

I have a below requirement and need your help in this regard.

I have two timestamps in a file i.e.

Code:
TimeBefore=2014-07-10.18.06.55
TimeAfter_1=2014-07-09.05.45.12
TimeAfter_2=2014-07-09.05.40.12

When I first run the script file, it sets the 'TimeBefore' to todays date.
When I run the script for second time it should set TimeAfter_1 to value as 'TimeBefore' and TimeAfter_2 to value as 'TimeBefore' but minus 5 minutes


Example:

First Time script is run:
Code:
TimeBefore=2014-07-10.18.06.55
TimeAfter_1=2014-07-09.05.45.12
TimeAfter_2=2014-07-09.05.40.12

Second Time Script is run:
Code:
TimeBefore=2014-07-10.18.06.55
TimeAfter_1=2014-07-10.18.06.55
TimeAfter_2=2014-07-10.18.01.55  ** 5 mins less from Time Before

I am able to achieve First Time script is run, but unable to get when second time script is run. Is there a way I can read the value of 'TimeBefore' and assign it to 'TimeAfter_1' & 'TimeAfter_2'

NOTE: This is in same file and all 3 variables will be on fixed line

Regards
Vrushank

Last edited by Don Cragun; 07-10-2014 at 06:20 AM.. Reason: Add CODE tags.
# 2  
Old 07-10-2014
How do you propose to keep track of whether you are in run #1 of the script, run #2 of the script, or run #3 of the script?

Please post your existing code if you want meaningful help.
# 3  
Old 07-10-2014
Hi,

I will be invoking this script from Informatica ETL Tool.

First run will set
Code:
TimeBefore=2014-07-10.18.06.55

. I am achieving this using SED command as below

Code:
cd /TWData/control/Param/ && sed "2s/=.*/=$(date +"%Y-%m-%d-%H.%M.%S" )/" FileA.prm > temp.prm && mv temp.prm FileA.prm

After I finish my processing I will invoke second run (which will be via ETL tool) I need to set 'TimeAfter_1' to value as 'TimeBefore' and 'TimeAfter_2' to value as 'TimeBefore' but minus 5 minutes

Hope this helps.

Regards,
Vrushank
# 4  
Old 07-10-2014
I would suggest you to have these timestamps in a file which will not be modified by any other process.

So, for the first run of the script you can print "TimeBefore" to $CURRENT_DATE. The other two will be NULL.

On the second run,

if "TimeBefore" is set then read the value, print "TimeAfter1" as "TimeBefore"
Reduce 5 minutes, then print as "TimeAfter2" as "Reduced_Value"


Hope this helps...
This User Gave Thanks to PikK45 For This Post:
# 5  
Old 07-10-2014
Thanks Pikk45 , but I am not able to get as to how I can read the value of "TimeBefore' and assign it to "TimeAfter1"

How can I read and assign the value of "TimeBefore" to "TimeAfter1"

- VP

---------- Post updated at 08:24 AM ---------- Previous update was at 07:54 AM ----------

Hi All,

I am partly successful with assigning "TimeBefore" to "TimeAfter_1". How can I assign "TimeAfter_2" as this should be 5 minutes less. I am on AIX 6.1 and it doesn't support normal date calc functions. Any help will be really appreciated

-Vrushank
# 6  
Old 07-10-2014
Code:
 perl -Mstrict -e 'sub iso_stamp{
       my $epoch=shift;my @time=localtime($epoch);
       return sprintf "%04d-%02d-%02d.%02d.%02d",$time[5]+1900,$time[4]+1,@time[3,2,1];
       }
my $epoch_now=time(); print iso_stamp($epoch_now),"\n",iso_stamp($epoch_now - 300),"\n";'
2014-07-10.14.33
2014-07-10.14.28

These 2 Users Gave Thanks to Skrynesaver For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Updating in file

hi, i have an csv(which is a month's log file containing userid and log in date ) file which has to be appended to another file say master.log.I need to compare the next month's log data to master.log file .In case, there is new log date for userid it has to get updated in master.log file or i... (2 Replies)
Discussion started by: preema
2 Replies

2. Shell Programming and Scripting

Help updating a file

I can not seem to figure out how to update the attached match.txt column 2 using update.txt. However, only the text before the period in updat.txt appears in match.txt. For example, in update.txt NM_001613.2 matches NM_001613 in match.txt, so is it possible to update the record in match.txt to... (8 Replies)
Discussion started by: cmccabe
8 Replies

3. Shell Programming and Scripting

updating a file with sed -help

I have a file of records all made up of single charactors that need to be updated using their row/column (the dashes represent spaces as the html formatting of this text box when it posts removes the "nonessential" white space between the charactors) file example A 1 c B 2 b C 3 a... (2 Replies)
Discussion started by: dboward
2 Replies

4. Shell Programming and Scripting

Reading from one file and updating other file with constant entries

Hi All, Thaks for the help in my last thread. I have one more question. I have two files with ldap entries in it. One file contains all the user LDAP parameter entries (26 MB) and other file contains only the user id's that have to be inactivated. Unix script has to read from the file that has... (8 Replies)
Discussion started by: Samingla
8 Replies

5. Solaris

Message file is not updating

Hi, Some how message file is not updating on solaris 8, but syslogd is running. Any help. It is urgent. (1 Reply)
Discussion started by: mokkan
1 Replies

6. UNIX for Dummies Questions & Answers

Updating a field in a File without creating temp file's

Hi Experts, I have a requirement where i need to update the below items in file, 1. END TIME 2. PREV_STATUS For the first time the PREV_status and end time of all job the job will be sysdate & NULL reply as below, Session_name,Load Type,Frequency,Seesion End time,Prev_Status... (2 Replies)
Discussion started by: prabhutkl
2 Replies

7. UNIX for Advanced & Expert Users

wtmpx file is not updating

Hi in my solaris 9 system wmptx file is not updating so it is not recording any login or logout or any other entry. can any one tell me how to solve this problem (0 Replies)
Discussion started by: aaysa123
0 Replies

8. Shell Programming and Scripting

awk updating one file with another, comparing, updating

Hello, I read and search through this wonderful forum and tried different approaches but it seems I lack some knowledge and neurones ^^ Here is what I'm trying to achieve : file1: test filea 3495; test fileb 4578; test filec 7689; test filey 9978; test filez 12300; file2: test filea... (11 Replies)
Discussion started by: mecano
11 Replies

9. Shell Programming and Scripting

Sed Help in Updating something only in one particular file.

Hi, The scenerio is that I want to replace a text in one particular line of a file. But when I am using the sed it's replacing all the occurences of that text. Like the file is: >cat test DNGGF10 :None :Test DNGGF11 :ABC :Test1 DNGGF12 :None :Test2 DNGGF13 :None :... (4 Replies)
Discussion started by: bisla.yogender
4 Replies

10. Shell Programming and Scripting

TO know whether file is updating or not

Hi All, I am new to scripting. my requirement is , I want to know whether the file(i.e., log file) is updating or not. It should search for every 15 min. If it is not updating means it needs to send out a automatic mail. can you please help me in this. (2 Replies)
Discussion started by: raj333
2 Replies
Login or Register to Ask a Question