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
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
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
Could this help you ?
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
Hi Pravin,
Thanks much for your quick response. I'm receiving the following errors, when executing this 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
$ 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