Sponsored Content
Top Forums Shell Programming and Scripting Update time stamp and replace values Post 302968806 by vinus on Tuesday 15th of March 2016 10:45:11 AM
Old 03-15-2016
Update time stamp and replace values

Can anyone please assist?

I need to grab each line between the lines "HEADER" and "TRAILER"

Each line contains two timestamps(Timestamp1) and (Timestamp2). I need to create two variables TIME_SUBSTRCT and TIME_ADD and

then recalculate the two timestamps using this logic:
START_TIME=Timestamp1 - ${TIME_SUBSTRACT}
END_TIME=Timestamp2 + ${TIME_ADD}
The final output should be each line with its new adjusted timestamps in place of the original timestamps.

eg. If timestamp1=09:17:00 and TIME_SUBSTRACT=10 , the START_TIME to be 09:07:00

If timestamp2=10:15:00 and TIME_ADD=15, the END_TIME to be 10:30:00

Code:
Input File:

HEADER
SERVER1 02/10/2016 10:13:00.000 02/10/2016 10:18:59.011 1123
SERVER2 02/10/2016 07:05:00.000 02/10/2016 08:10:59.011 1234
SERVER3 02/10/2016 06:32:00.000 02/10/2016 07:37:59.012 1567
SERVER4 02/11/2016 03:14:00.000 02/11/2016 08:19:59.134 1678
SERVER5 02/10/2016 11:48:00.000 02/10/2016 06:53:59.444 1790
TRAILER

Expected output:
Code:
SERVER1 02/10/2016 10:03:00.000 02/10/2016 10:33:59.011 1123
SERVER2 02/10/2016 06:55:00.000 02/10/2016 08:25:59.011 1234
SERVER3 02/10/2016 06:22:00.000 02/10/2016 07:52:59.012 1567
SERVER4 02/11/2016 03:04:00.000 02/11/2016 08:34:59.134 1678
SERVER5 02/10/2016 11:38:00.000 02/10/2016 07:08:59.444 1790

Code:
My Code:
######################
TIME_SUBSTRACT=10
TIME_ADD=15
InputFile=Inputfile.txt
ExtractFile=Extractfile.txt

awk '/HEADER/ {flag=1;next} /TRAILER/{flag=0} flag {print}' ${InputFile}  >${ExtractFile}

ReplaceValue()
{
awk  -v var="${START_TIME}" -v var1="${END_TIME}"  '{$3=var;$5=var1}1' ${ExtractFile} >outputfile.txt
}

cat ${ExtractFile} | while read line
do
TIMESTAMP1=`echo $line | awk '{print substr($3,1,8)}'`
TIMESTAMP2=`echo $line | awk '{print substr($5,1,8)}'`
START_TIME=`awk -v var="${TIME_SUBSTRACT}" -v var1="${TIMESTAMP1}" 'BEGIN{print strftime("%H:%M:%S",var1-(var*60))}'`
END_TIME=`awk -v var="${TIME_ADD}" -v var1="${TIMESTAMP2}" 'BEGIN{print strftime("%H:%M:%S",var1+(var*60))}'`
ReplaceValue
done

Few issues 1) Not getting correct start time and end time. 2) while replacing the older timestamp with new timestamp last part of columns 3 and 5 are missing(Ex:000,011). Tried using substr and its not working.

Thanks for your help in advance.

---------- Post updated 03-15-16 at 09:45 AM ---------- Previous update was 03-14-16 at 02:09 PM ----------

I'm getting correct start time and end time. I should be able to fix the code.

Thanks

Last edited by vinus; 03-14-2016 at 05:00 PM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

greping with time stamp

Hi all, I want to grep a file name with time stamp as 30 minutes how can i??. Ex I will getting outputs in a file every minutes I want to grep it by a time intervals of 30 and show it . Any help will be great ! Thanks, Arun. (1 Reply)
Discussion started by: arunkumar_mca
1 Replies

2. UNIX for Dummies Questions & Answers

checking time stamp

Hi, I am having a script in which I am again calling a script, but before calling that script I need to perform a time check (say 1 - 2 am i.e. I would be able to call that script if time is between 1:00 am and 2:00 am) but this time stamp needs to be configurable. can anybody suggest me how... (7 Replies)
Discussion started by: Manvar Khan
7 Replies

3. Shell Programming and Scripting

Time stamp calculation

Hi all; I'm relatively new to scripting,I am working on a monitoring script.....where in i have to write subroutine which does the follows: It will check the time stamp of a file ( Oracle remarchive files) and compare it with existing time.If the time difference happen to be more than 90... (6 Replies)
Discussion started by: maverick_here
6 Replies

4. Shell Programming and Scripting

regarding time stamp

hi everyone i am facing a strange problem here suppose content of my file is a=1,2,3 b=2,3,4 c=4,5,6 time= now the problem is i want to add value in front of time variable and the value should be i format only "HHMMSS" so it should be like this a=1,2,3 b=2,3,4 c=4,5,6... (3 Replies)
Discussion started by: aishsimplesweet
3 Replies

5. Shell Programming and Scripting

How to get time duration between two human readable time stamp in Unix?

Here is two time I have: Jul 12 16:02:01 Jul 13 01:02:01 and how can I do a simple match to get difference between two time which is 09:00:00 Thanks in advance. (3 Replies)
Discussion started by: ford99
3 Replies

6. Shell Programming and Scripting

change and replace time stamp

Hi, I want to convert normal time stamp to unix time stamp to a filename. coz our ssytem will pick depends on unix timestamp format . the filenames are as shown below fie names are stored in file say temp.txt. MLFG2_cDomHTTPstats_SAB15-1_1318482447.dat... (2 Replies)
Discussion started by: raghavendra.nsn
2 Replies

7. Solaris

System time and Cron time stamp not matching

On Solaris 10 server the system date won't match with the timestamp on files created by a cron jobs, Please help here is what i get when i check for system date infodba-ie10ux014:/tcpdv1_ie10/tcadmin/bin\n\r-> date Tue Apr 24 15:27:43 GMT 2012at same time i executed a cron job, and checked... (4 Replies)
Discussion started by: karghum
4 Replies

8. Shell Programming and Scripting

Time stamp Difference

I have a log file which wrote time stamp like this 2013-02-11 00:46:40.389037 2013-02-12 11:46:40.197045 can any one help me to get the time stamp difference of these two line in seconds. (4 Replies)
Discussion started by: netdbaind
4 Replies

9. UNIX for Advanced & Expert Users

Need mtime with time stamp

hi all find /folder1 -mtime 1 >folder1 with the above command , I can get the output of all the files which are modified(within folders and sub folders of folder1) in the last 24 hours. but the listed files output , does not contain the time stamp with it. I request you to give... (4 Replies)
Discussion started by: sidharthmellam
4 Replies

10. Shell Programming and Scripting

Logs between two time stamp

I am creating log monitoring script and stuck up to get the logs between two time stamp. can you please help me to create the script to get the logs between two time stamp, for example, I need the complete logs between # Time: 150328 1:30:10 and # Time: 150328 19:10:57 OS : Cent OS 6.x... (8 Replies)
Discussion started by: zenkarthi
8 Replies
kproplog(1M)						  System Administration Commands					      kproplog(1M)

NAME
kproplog - display the contents of the Kerberos principal update log SYNOPSIS
/usr/sbin/kproplog [-h | -e num] DESCRIPTION
The kproplog displays the contents of the Kerberos principal update log to standard output. This command can be used to keep track of the incremental updates to the principal database, which is enabled by default. The /var/krb5/principal.ulog file contains the update log main- tained by the kadmind(1M) process on the master KDC server and the kpropd(1M) process on the slave KDC servers. When updates occur, they are logged to this file. Subsequently any KDC slave configured for incremental updates will request the current data from the master KDC and update their principal.ulog file with any updates returned. The kproplog command can only be run on a KDC server by someone with privileges comparable to the superuser. It will display update entries for that server only. If no options are specified, the summary of the update log is displayed. If invoked on the master, all of the update entries are also dis- played. When invoked on a slave KDC server, only a summary of the updates are displayed, which includes the serial number of the last update received and the associated time stamp of the last update. OPTIONS
The following options are supported: -h Display a summary of the update log. This information includes the database version number, state of the database, the number of updates in the log, the time stamp of the first and last update, and the version number of the first and last update entry. -e num Display the last num update entries in the log. This is useful when debugging synchronization between KDC servers. -v Display individual attributes per update. An example of the output generated for one entry: Update Entry Update serial # : 4 Update operation : Add Update principal : test@EXAMPLE.COM Update size : 424 Update committed : True Update time stamp : Fri Feb 20 23:37:42 2004 Attributes changed : 6 Principal Key data Password last changed Modifying principal Modification time TL data FILES
/var/krb5/principal.ulog The update log file for incremental propagation. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWkdcu | +-----------------------------+-----------------------------+ |Interface Stability |Evolving | +-----------------------------+-----------------------------+ SEE ALSO
kpasswd(1), gkadmin(1M), kadmin(1M), kadmind(1M), kdb5_util(1M), kprop(1M), kpropd(1M), kadm5.acl(4), kdc.conf(4), attributes(5), ker- beros(5) SunOS 5.11 29 Mar 2004 kproplog(1M)
All times are GMT -4. The time now is 01:04 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy