Sponsored Content
Top Forums Shell Programming and Scripting How to find date Difference in AWK/GAWK with millisecond precision Post 302075413 by jim mcnamara on Friday 2nd of June 2006 12:50:51 PM
Old 06-02-2006
You can do this with the timeval struct in C. I don't know of a way to do this in awk - especially if you have values that span minutes or hours.
 

10 More Discussions You Might Find Interesting

1. Programming

find CPU Time for a function (subsecond precision)

Hi, I need to time a certain function in my C/C++ code and I am experiencing some difficulties. I timed it using wallclock time so I know that it takes approximately 500-600 microseconds with gettimeofday(&start, NULL); // my function call gettimeofday(&end, NULL); answer = (end.tv_sec -... (2 Replies)
Discussion started by: zynnel
2 Replies

2. Shell Programming and Scripting

Select ip and date using sed or gawk

1.56.253.48 - - "GET " 1.6.253.48 - - "GET " 1.65.253.48 - - "GET " 1.65.253.48 - - "GET " 1.63.53.48 - - "GET " 1.65.253.48 - - "GET " 1.16.23.48 - - "GET " 1.64.25.48 - - "GET " need command which give the output 1.6.253.48 - 09/Nov/2009:07:02:24 1.65.253.48 -... (7 Replies)
Discussion started by: sagar_evc
7 Replies

3. Shell Programming and Scripting

Double-precision result (awk)

hi, I am a new awk user, now i want to change my result from 1 ca 0.2057422D-01 -0.7179106D-02 -0.5600872D-02 2 o 0.2463722D-01 -0.1554542D-01 0.3110649D-01 3 h -0.1068047D-01 0.1016889D-01 -0.4088230D-02 to 1 ca 0.02057422 -0.007179106 -0.005600872 2 o 0.02463722 -0.01554542 ... (4 Replies)
Discussion started by: wanchem
4 Replies

4. Shell Programming and Scripting

Find file size difference in two files using awk

Hi, Could anyone help me to solve this problem? I have two files "f1" and "f2" having 2 fields in each, a) file size and b) file name. The data are almost same in both the files except for few and new additional lines. Now, I have to find out and print the output as, the difference in the... (3 Replies)
Discussion started by: royalibrahim
3 Replies

5. Shell Programming and Scripting

Get timestamp with millisecond precision

Hi All, could any body let me know. how to get timestamp with millisecond precision in unix bash shell. example -->2005-12-06- 4-22-35-195 please help me. Thanks, Krupa:wall: (3 Replies)
Discussion started by: krupasindhu18
3 Replies

6. Shell Programming and Scripting

Gawk output difference

Why the below option2 doesn't fetch similar output as option1 ? I am on linux. $cat test 2013-01-01-00.25.43.643845 Option1: cat test | gawk -F"-" ' {print $2 " " $3 " " $1}' 01 01 2013 Option2: cat test | gawk '{FS="-"} {print $2 " " $3 " " $1}' 2013-01-01-00.25.43.643845 (5 Replies)
Discussion started by: Shivdatta
5 Replies

7. Shell Programming and Scripting

Find week of the year for given date using date command inside awk

Hi all, Need an urgent help on the below scenario. script: awk -F"," 'BEGIN { #some variable assignment} { #some calculation and put values in array} END { year=#getting it from array and assume this will be 2014 month=#getting it from array and this will be 05 date=#... (7 Replies)
Discussion started by: vijaidhas
7 Replies

8. Shell Programming and Scripting

Find and awk with today's date

Hi All, Solaris 10 o/s With your help I developed the following script. find /oracle/diag/rdbms/*/*/trace -type f -name '*d00*.trc' -mtime 0 -exec egrep –c 'NS Primary Error' '{}' '+' which returns the counts I needed nelow: /oracle/diag/rdbms/musidp/musidp/trace/abcdef_d001_21751.trc:15... (9 Replies)
Discussion started by: bdby
9 Replies

9. UNIX for Advanced & Expert Users

Subtract millisecond Timestamps with awk

Hello, am not able to subtract timestamps in milliseconds. I extract the timestamp as a string, and then try to subtract the two, but since it is a string, system just outputs 0 awk -F"," 'substr($1,0,13) - substr($2,0,013)' File where $1 and $2 are the timestamps in the format... (4 Replies)
Discussion started by: sidnow
4 Replies

10. UNIX for Beginners Questions & Answers

In HP-UX how to find the date time difference ?

Hello, In HP-UX how to find the date time difference ? Start time: 28-APR-2019 21:36:01 End time : 29-APR-2019 00:36:04 ---------------------- Difference is ---------------------- Much appreciate any pointer or view on this. ... (3 Replies)
Discussion started by: Siva SQL
3 Replies
TIMEVAL(3)						   BSD Library Functions Manual 						TIMEVAL(3)

NAME
timeval, timespec, itimerval, itimerspec, bintime -- time structures SYNOPSIS
#include <sys/time.h> void TIMEVAL_TO_TIMESPEC(struct timeval *tv, struct timespec *ts); void TIMESPEC_TO_TIMEVAL(struct timeval *tv, struct timespec *ts); DESCRIPTION
The <sys/time.h> header, included by <time.h>, defines various structures related to time and timers. 1. The following structure is used by gettimeofday(2), among others: struct timeval { time_t tv_sec; suseconds_t tv_usec; }; The tv_sec member represents the elapsed time, in whole seconds. The tv_usec member captures rest of the elapsed time, represented as the number of microseconds. 2. The following structure is used by nanosleep(2), among others: struct timespec { time_t tv_sec; long tv_nsec; }; The tv_sec member is again the elapsed time in whole seconds. The tv_nsec member represents the rest of the elapsed time in nanosec- onds. A microsecond is equal to one millionth of a second, 1000 nanoseconds, or 1/1000 milliseconds. To ease the conversions, the macros TIMEVAL_TO_TIMESPEC() and TIMESPEC_TO_TIMEVAL() can be used to convert between struct timeval and struct timespec. 3. The following structure is used by setitimer(2), among others: struct itimerval { struct timeval it_interval; struct timeval it_value; }; 4. The following structure is used by timer_settime(2), among others: struct itimerspec { struct timespec it_interval; struct timespec it_value; }; Both struct itimerval and struct itimerspec are used to specify when a timer expires. Generally, it_interval specifies the period between successive timer expirations. A value zero implies that the alarm will fire only once. If it_value is non-zero, it indicates the time left to the next timer expiration. A value zero implies that the timer is disabled. 5. The following structure is used by bintime(9), among others: struct bintime { time_t sec; uint64_t frac; }; The sec member specifies the time in seconds and frac represents a 64-bit fraction of seconds. The struct bintime is meant to be used in the kernel only. It is further described in timecounter(9). EXAMPLES
It can be stressed that the traditional UNIX timeval and timespec structures represent elapsed time, measured by the system clock (see hz(9)). The following sketch implements a function suitable for use in a context where the timespec structure is required for a conditional timeout: static void example(struct timespec *spec, time_t minutes) { struct timeval elapsed; (void)gettimeofday(&elapsed, NULL); _DIAGASSERT(spec != NULL); TIMEVAL_TO_TIMESPEC(&elapsed, spec); /* Add the offset for timeout in minutes. */ spec->tv_sec = spec->tv_sec + minutes * 60; } A better alternative would use the more precise clock_gettime(2). SEE ALSO
timeradd(3), tm(3), bintime_add(9) BSD
April 12, 2011 BSD
All times are GMT -4. The time now is 01:57 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy