Sponsored Content
Top Forums Shell Programming and Scripting Calculate difference in timestamps based on unique column value Post 302719605 by DGPickett on Monday 22nd of October 2012 04:55:11 PM
Old 10-22-2012
The ksh does not have date arithmetic, but you can decompose the lines, fields to the integers and write some calendar subroutines to do the subtraction. I would use sed to turn the various numbers into variable settings:
Code:
$( echo $f |sed -n '
  s/^\(..\)\/\(..\)\/\(....\) \(..\):\(..\)/yy=\3 mo=\1 dy=\2 hh=\4 mi=\5 ss=\6/p'
 ' )

If you are inclined to reduce them to something like integer UNIX Zulu time, I have found it best to shift the epoch slightly (March 1, 1968) so the first days, month days for March through January, February is whatever is left over. The new epoch has 365x4+1 day quad-years from 3/1/1900 to 2/28/2100 as 2000 was a leap year century.
 

10 More Discussions You Might Find Interesting

1. Solaris

Difference between two timestamps

I'm writting a script to find the difference between two timestamp. One field i get on delivery time of the file like 07:17 AM and other is my SLA time 06:30 AM I need to find the difference between these two time (time exceeded to meet SLA). Need some suggestions. (8 Replies)
Discussion started by: raman1605
8 Replies

2. Shell Programming and Scripting

Difference between two timestamps Contd..

There was this thread earlier with the same name and the solution provided was excellent. Here is the solution to find diffrenc between two timestamp $ cat timestamp #! /usr/bin/ksh echo enter first time stamp read TIME1 echo enter second time stamp read TIME2 H1=${TIME1%:+()}... (3 Replies)
Discussion started by: Shellslave
3 Replies

3. Shell Programming and Scripting

Calculate difference between consecutive data points in a column from a file

Hi, I have a file with one column data (sample below) and I am trying to write a shell script to calculate the difference between consecutive data valuse i.e Var = Ni -N(i-1) 0.3141 -3.6595 0.9171 5.2001 3.5331 3.7022 -6.1087 -5.1039 -9.8144 1.6516 -2.725 3.982 7.769 8.88 (5 Replies)
Discussion started by: malandisa
5 Replies

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

5. Shell Programming and Scripting

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 ======== 08/23/2012 12:36:09 JOB_5340 08/23/2012 12:36:14 JOB_5340 08/23/2012... (2 Replies)
Discussion started by: asnandhakumar
2 Replies

6. Shell Programming and Scripting

Calculate 2nd Column Based on 1st Column

Dear All, I have input file like this. input.txt CE2_12-15 3950.00 589221.0 9849709.0 768.0 CE2_12_2012 CE2_12-15 3949.00 589199.0 9849721.0 768.0 CE2_12_2012 CE2_12-15 3948.00 589178.0 9849734.0 768.0 CE2_12_2012 CE2_12-52 1157.00 ... (3 Replies)
Discussion started by: attila
3 Replies

7. Shell Programming and Scripting

Calculate the average of a column based on the value of another column

Hi, I would like to calculate the average of column 'y' based on the value of column 'pos'. For example, here is file1 id pos y c 11 1 220 aa 11 4333 207 f 11 5333 112 ee 11 11116 305 e 11 11117 310 r 11 22228 781 gg 11 ... (2 Replies)
Discussion started by: jackken007
2 Replies

8. Shell Programming and Scripting

Finding difference in 2 different timestamps

Legends, I have a requirement to run the script exactly after one hour of completion of dependent script. Eg: Script B should run after one hour on the completion of Script A. I got the time stamps using following variables. these scripts runs in autosys > DATE=`date +%H:%M` >... (4 Replies)
Discussion started by: sdosanjh
4 Replies

9. Linux

To get all the columns in a CSV file based on unique values of particular column

cat sample.csv ID,Name,no 1,AAA,1 2,BBB,1 3,AAA,1 4,BBB,1 cut -d',' -f2 sample.csv | sort | uniq this gives only the 2nd column values Name AAA BBB How to I get all the columns of CSV along with this? (1 Reply)
Discussion started by: sanvel
1 Replies

10. Shell Programming and Scripting

Calculate 5th percentile based on another column

I would like to have some help in calculating 5th percentile value of column 2 for each site, the input is like below:site val1 val2 002 10 25.3 002 20 25.3 002 30 25.3 002 40 20 002 50 20 002 60 20 002 70 20 002 80 30 002 90 30 002 100 30 002 120 30 003 20 30.3 003 20 30.3 003 30 20... (2 Replies)
Discussion started by: wuhuai
2 Replies
CLOCKDIFF(8)						 System Manager's Manual: iputils					      CLOCKDIFF(8)

NAME
clockdiff - measure clock difference between hosts SYNOPSIS
clockdiff [-o] [-o1] destination DESCRIPTION
clockdiff Measures clock difference between us and destination with 1 msec resolution using ICMP TIMESTAMP [2] packets or, optionally, IP TIMESTAMP option [3] option added to ICMP ECHO. [1] OPTIONS
-o Use IP TIMESTAMP with ICMP ECHO instead of ICMP TIMESTAMP messages. It is useful with some destinations, which do not support ICMP TIMESTAMP (f.e. Solaris <2.4). -o1 Slightly different form of -o, namely it uses three-term IP TIMESTAMP with prespecified hop addresses instead of four term one. What flavor works better depends on target host. Particularly, -o is better for Linux. WARNINGS
o Some nodes (Cisco) use non-standard timestamps, which is allowed by RFC, but makes timestamps mostly useless. o Some nodes generate messed timestamps (Solaris>2.4), when run xntpd. Seems, its IP stack uses a corrupted clock source, which is synchro- nized to time-of-day clock periodically and jumps randomly making timestamps mostly useless. Good news is that you can use NTP in this case, which is even better. o clockdiff shows difference in time modulo 24 days. SEE ALSO
ping(8), arping(8), tracepath(8). REFERENCES
[1] ICMP ECHO, RFC0792, page 14. [2] ICMP TIMESTAMP, RFC0792, page 16. [3] IP TIMESTAMP option, RFC0791, 3.1, page 16. AUTHOR
clockdiff was compiled by Alexey Kuznetsov <kuznet@ms2.inr.ac.ru>. It was based on code borrowed from BSD timed daemon. It is now main- tained by YOSHIFUJI Hideaki <yoshfuji@skbuff.net>. SECURITY
clockdiff requires CAP_NET_RAWIO capability to be executed. It is safe to be used as set-uid root. AVAILABILITY
clockdiff is part of iputils package and the latest versions are available in source form at http://www.skbuff.net/iputils/iputils-cur- rent.tar.bz2. iputils-101006 12 April 2011 CLOCKDIFF(8)
All times are GMT -4. The time now is 11:55 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy