Transpose timestamp based on column values and calculate time difference


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Transpose timestamp based on column values and calculate time difference
# 1  
Old 10-15-2012
Transpose timestamp based on column values and calculate time difference

Hello Expert,

I need to transpose Date-Timestamp based on same column values and calculate time difference. The input file would be as below and required output is mentioned in the bottom

INPUT File
========
Code:
08/23/2012 12:36:09	JOB_5340
08/23/2012 12:36:14	JOB_5340
08/23/2012 12:36:22	JOB_5350
08/23/2012 12:36:26	JOB_5350

OUTPUT
======
Code:
08/23/2012 12:36:14,08/23/2012 12:36:09,JOB_5340,00:00:05
08/23/2012 12:36:26,08/23/2012 12:36:22,JOB_5350,00:00:04

Many Thanks for your quick response
NK

Last edited by Franklin52; 10-15-2012 at 03:52 AM.. Reason: Please use code tags for data and code samples
# 2  
Old 10-15-2012
Could this help you ?
Code:
paste - - < Filename| while read line
do
dt2=$(echo $line | awk '{print $4" "$5}')
dt1=$(echo $line | awk '{print $1" "$2}')
echo -n $(echo $line | awk '{print $4,$5","$1,$2","$3","}')
echo $(($(date -d"$dt2" '+%s') - $(date -d"$dt1" '+%s')))
done

# 3  
Old 10-16-2012
Hi Pravin,

Thanks much for your quick response. I'm receiving the following errors, when executing this code :
Code:
$ transpose.log | while read line
> do
> (dt2=$(echo $line | awk '{print $4" "$5}')
> dt1=$(echo $line | awk '{print $1" "$2}')
> echo -n $(echo $line | awk '{print $4,$5","$1,$2","$3","}')
> echo $(($(date -d"$dt2" '+%s') - $(date -d"$dt1" '+%s')))
> done
ksh: 0403-057 Syntax error: `done' is not expected.

Thanks,
NK

---------- Post updated at 11:07 PM ---------- Previous update was at 12:01 PM ----------

Hi Pravin, This is the error msg, I get for this code:

Can someone help get a clean output

Code:
$ cat transpose.log | while read line
> do
> dt2=$(echo $line | awk '{print $4" "$5}')
> dt1=$(echo $line | awk '{print $1" "$2}')
> echo -n $(echo $line | awk '{print $4,$5","$1,$2","$3","}')
> echo $(($(date -d"$dt2" '+%s') - $(date -d"$dt1" '+%s')))
> done
-n ,08/23/2012 12:36:09,JOB_5340,
date: Not a recognized flag: d
Usage: date [-u] [+"Field Descriptors"]
date: Not a recognized flag: d
Usage: date [-u] [+"Field Descriptors"]
ksh[6]:  - : 0403-053 Expression is not complete; more tokens expected.

Many Thanks,
NK
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Transpose from row to column using timestamp in first column

Gents, Transpose from row to column, taking in consideration the first column, which contends the date. Input file 72918,111000009,111000009,111000009,111000009,111000009,111000009,111000009,111000009,111000009 72918,2356,2357,2358,2359,2360,2361,2362,2363,2364 72918,0,0,0,0,0,0,0,0,0... (12 Replies)
Discussion started by: jiam912
12 Replies

2. Shell Programming and Scripting

Calculate time difference

I have time in a file in HH:MM:SS format as it contents(its not the file creation time). i need this to be converted to epoch time or time since 1970. The time is written into that file by a script, which i cannot modify. Im using AIX machine $ cat abc.txt 10:29:34 (2 Replies)
Discussion started by: gpk_newbie
2 Replies

3. Shell Programming and Scripting

Calculate difference in timestamps based on unique column value

Hi Friends, Require a quick help to write the difference between 2 timestamps based on a unique column value: Input file: 08/23/2012 12:36:09,JOB_5340,08/23/2012 12:36:14,JOB_5340 08/23/2012 12:36:22,JOB_5350,08/23/2012 12:36:26,JOB_5350 08/23/2012 13:08:51,JOB_5360,08/23/2012... (4 Replies)
Discussion started by: asnandhakumar
4 Replies

4. Shell Programming and Scripting

Based on the first & last timestamp of the file, need to calculate the time taken to complete

Below is the sample file: 287 DEBUG syndesis.pb.util.ITraceManager - syOID=ELntNetwork:1005Mon Oct 15 17:18:21 IST 2012 <ELClientManagerenEmsSession() > Setting Java Properties 287 DEBUG syndesis.pb.util.ITraceManager - syOID=ELntNetwork:1005Mon Oct 15 17:18:21 IST 2012... (1 Reply)
Discussion started by: ashok.kumar
1 Replies

5. Shell Programming and Scripting

Transpose field names from column headers to values in one column

Hi All, I'm looking for a script which can transpose field names from column headers to values in one column. for example, the input is: IDa;IDb;IDc;PARAM1;PARAM2;PARAM3; a;b;c;p1val;p2val;p3val; d;e;f;p4val;p5val;p6val; g;h;i;p7val;p8val;p9val; into the output like this: ... (6 Replies)
Discussion started by: popesk
6 Replies

6. Shell Programming and Scripting

Calculate age of a file | calculate time difference

Hello, I'm trying to create a shell script (#!/bin/sh) which should tell me the age of a file in minutes... I have a process, which delivers me all 15 minutes a new file and I want to have a monitoring script, which sends me an email, if the present file is older than 20 minutes. To do... (10 Replies)
Discussion started by: worm
10 Replies

7. Shell Programming and Scripting

Calculate difference between two successive values

Hi, I have a file containing timestamps (at micro-seconds granularity). It looks like the following: 06:49:42.383818 06:49:42.390190 06:49:42.392308 06:49:42.392712 06:49:42.393437 06:49:42.393960 06:49:42.402115 Now I need a sed/awk script to take the difference of two successive... (2 Replies)
Discussion started by: sajal.bhatia
2 Replies

8. Shell Programming and Scripting

How to calculate time difference between start and end time of a process!

Hello All, I have a problem calculating the time difference between start and end timings...! the timings are given by 24hr format.. Start Date : 08/05/10 12:55 End Date : 08/09/10 06:50 above values are in mm/dd/yy hh:mm format. Now the thing is, 7th(08/07/10) and... (16 Replies)
Discussion started by: smarty86
16 Replies

9. Shell Programming and Scripting

How to calculate the time difference.

Hi All, I've written a script which reads all the systems backup information and saves it in a log file. ssh -l ora${sid} ${primaryhost} "tail -1 /oracle/$ORACLE_SID/sapbackup/back$ORACLE_SID.log" | awk '{print $3,$4,$5,$6}' >> ${RESULTFILE} The output comes as below: 2008-09-30 06.00.01... (2 Replies)
Discussion started by: suri.tyson
2 Replies

10. Shell Programming and Scripting

How to calculate this time difference

Hi, Please help me in calculating the time difference between below mentioned timestamps. a=07/17/2007 02:20:00 AM MST b=07/17/2007 02:07:46 AM MST Thanks (2 Replies)
Discussion started by: Prat007
2 Replies
Login or Register to Ask a Question