Sponsored Content
Top Forums UNIX for Advanced & Expert Users Subtract millisecond Timestamps with awk Post 303025079 by RudiC on Tuesday 23rd of October 2018 05:10:19 PM
Old 10-23-2018
Quote:
Originally Posted by sidnow
How should I do that?
Now - how many minutes does an hour have? And how many seconds a minute? Do you know about awk's split command?


BTW, your attempt will print nothing if the hours are the same, and the input line if different.

Last edited by RudiC; 10-23-2018 at 06:15 PM..
 

10 More Discussions You Might Find Interesting

1. Programming

Help! Display Time with Millisecond

Hi All, Urgent! Just a newbie needing advice. Has anybody have a sample C script code in Unix to display time with milliseconds? Most of the research I'm doing is up to the seconds format only. Thanks! Leidail (3 Replies)
Discussion started by: rezlez
3 Replies

2. Shell Programming and Scripting

How to find date Difference in AWK/GAWK with millisecond precision

Hi, I have a log file that has the date in this format "2006-05-30_13:14:04,256". I need to find the time difference between two log entries in milliseconds. How to achieve this in AWK/GAWK script? :confused: (2 Replies)
Discussion started by: omprasad
2 Replies

3. Shell Programming and Scripting

AWK solution to subtract multiple columns of numbers

Hope somebody is happy. NR==1 { num_columns=split( $0, menuend ); next; } { split( $0, substrend ); for ( i=1; i<=NF; i++ ) { minuend -= substrend; } } END { print "Result:"; for ( i=1; i<=num_columns; i++ ) { printf(... (3 Replies)
Discussion started by: awkward
3 Replies

4. Shell Programming and Scripting

add and subtract specific row using awk

Hi Folks I have tried awk command to conditionally add or subtract value from specific row in a file. The test file looks like: # cat test.txt cont x y Max 0.3 0.9 Min 0.2 0.9 diff 0.1 0 # awk '{for (i=2; i <=NF; i++) if ($i== "0") $i=$i+0.2; print}' test.txt Output: cont... (1 Reply)
Discussion started by: dixits
1 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

Compare & subtract lines in files by column using awk.

I have two files with similar column pattern as given below : 2 sample lines from file1 are given below. 18 12630 . G T 49.97 . AC=2;AF=1.00;AN=2;DP=3;Dels=0.00;FS=0.000;HRun=0;HaplotypeScore=0.0000;MQ=60.00;MQ0=0;NDA=1;QD=16.66;SB=-0.01 GT:AD:DP:GQ:PL ... (2 Replies)
Discussion started by: vaibhavvsk
2 Replies

7. Shell Programming and Scripting

To print lines between 2 timestamps using awk|sed and regex

Hi, I am using the following code to fetch lines that are generated in last 1 hr . Hence, I am using date function to calculate -last 1 hr & the current hr and then somehow use awk (or sed-if someone could guide me better) with some regex pattern. dt_1=`date +%h" "%d", "%Y\ %l -d "1 hour... (10 Replies)
Discussion started by: sarah-alikhan31
10 Replies

8. UNIX for Dummies Questions & Answers

awk to add/subtract an integer to/from each entry in columns?

---------- Post updated at 01:58 PM ---------- Previous update was at 01:48 PM ---------- For some reason my question is not getting printed. Here are the details: Greetings. I would like to add/subtact an integer to/from two columns of integers. I feel like this should be easy using awk... (3 Replies)
Discussion started by: Twinklefingers
3 Replies

9. Shell Programming and Scripting

awk to subtract from values in file

data.txt: 0,mq_conn_open_error,1444665949,734,/PROD/G/cicsitlp/sys/unikixmain.log,64K,mq_conn_open_error,62022,0,733--734 0,mq_conn_open_error,1444666249,734,/PROD/G/cicsitlp/sys/unikixmain.log,64K,mq_conn_open_error,62022,0,734--734... (7 Replies)
Discussion started by: SkySmart
7 Replies

10. HP-UX

awk command in hp UNIX subtract 30 days automatically from current date without date illegal option

current date command runs well awk -v t="$(date +%Y-%m-%d)" -F "'" '$1 < t' myname.dat subtract 30 days fails awk -v t="$(date --date="-30days" +%Y-%m-%d)" -F "'" '$1 < t' myname.dat awk command in hp unix subtract 30 days automatically from current date without date illegal option error... (20 Replies)
Discussion started by: kmarcus
20 Replies
PARSE_TIME(3)						   BSD Library Functions Manual 					     PARSE_TIME(3)

NAME
parse_time, print_time_table, unparse_time, unparse_time_approx, -- parse and unparse time intervals LIBRARY
The roken library (libroken, -lroken) SYNOPSIS
#include <parse_time.h> int parse_time(const char *timespec, const char *def_unit); void print_time_table(FILE *f); size_t unparse_time(int seconds, char *buf, size_t len); size_t unparse_time_approx(int seconds, char *buf, size_t len); DESCRIPTION
The parse_time() function converts a the period of time specified in into a number of seconds. The timespec can be any number of <number unit> pairs separated by comma and whitespace. The number can be negative. Number without explicit units are taken as being def_unit. The unparse_time() and unparse_time_approx() does the opposite of parse_time(), that is they take a number of seconds and express that as human readable string. unparse_time produces an exact time, while unparse_time_approx restricts the result to only include one units. print_time_table() prints a descriptive list of available units on the passed file descriptor. The possible units include: second, s minute, m hour, h day week seven days month 30 days year 365 days Units names can be arbitrarily abbreviated (as long as they are unique). RETURN VALUES
parse_time() returns the number of seconds that represents the expression in timespec or -1 on error. unparse_time() and unparse_time_approx() return the number of characters written to buf. if the return value is greater than or equal to the len argument, the string was too short and some of the printed characters were discarded. EXAMPLES
#include <stdio.h> #include <parse_time.h> int main(int argc, char **argv) { int i; int result; char buf[128]; print_time_table(stdout); for (i = 1; i < argc; i++) { result = parse_time(argv[i], "second"); if(result == -1) { fprintf(stderr, "%s: parse error ", argv[i]); continue; } printf("-- "); printf("parse_time = %d ", result); unparse_time(result, buf, sizeof(buf)); printf("unparse_time = %s ", buf); unparse_time_approx(result, buf, sizeof(buf)); printf("unparse_time_approx = %s ", buf); } return 0; } $ ./a.out "1 minute 30 seconds" "90 s" "1 y -1 s" 1 year = 365 days 1 month = 30 days 1 week = 7 days 1 day = 24 hours 1 hour = 60 minutes 1 minute = 60 seconds 1 second -- parse_time = 90 unparse_time = 1 minute 30 seconds unparse_time_approx = 1 minute -- parse_time = 90 unparse_time = 1 minute 30 seconds unparse_time_approx = 1 minute -- parse_time = 31535999 unparse_time = 12 months 4 days 23 hours 59 minutes 59 seconds unparse_time_approx = 12 months BUGS
Since parse_time() returns -1 on error there is no way to parse "minus one second". Currently "s" at the end of units is ignored. This is a hack for English plural forms. If these functions are ever localised, this scheme will have to change. HEIMDAL
October 31, 2004 HEIMDAL
All times are GMT -4. The time now is 08:04 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy