Subtract millisecond Timestamps with awk

Tags
advanced, awk, millisecond, rac, times

 
Thread Tools Search this Thread
# 1  
Old 10-23-2018
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

Code:
awk -F"," 'substr($1,0,13) - substr($2,0,013)' File

where $1 and $2 are the timestamps in the format HH:MM:SS.000

I have seen the usage of date -d command, but not sure how to pass it to the command line as arguments to awk.

Note the File contains 1000 rows
# 2  
Old 10-23-2018
Try converting "HH:MM:SS" to seconds. Will the timestamps cross midnight? Month end? Year end?
# 3  
Old 10-23-2018
How should I do that? With the date command? The timestamps wont cross midnight, it begins from midnight until 23:59:59.xxx
# 4  
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..
# 5  
Old 10-24-2018
You can calculate seconds from HH:MM:SS via seconds+(minutes*60)+(hours*60*60)

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
awk command in hp UNIX subtract 30 days automatically from current date without date illegal option kmarcus HP-UX 11 3 Weeks Ago 11:01 AM
awk to subtract from values in file SkySmart Shell Programming and Scripting 7 10-15-2015 08:08 AM
awk to add/subtract an integer to/from each entry in columns? Twinklefingers UNIX for Dummies Questions & Answers 3 01-02-2014 04:30 PM
To print lines between 2 timestamps using awk|sed and regex sarah-alikhan31 Shell Programming and Scripting 10 04-09-2013 01:13 PM
Compare & subtract lines in files by column using awk. vaibhavvsk Shell Programming and Scripting 2 01-14-2013 12:53 AM
Get timestamp with millisecond precision krupasindhu18 Shell Programming and Scripting 3 06-07-2012 02:08 AM
add and subtract specific row using awk dixits Shell Programming and Scripting 1 04-12-2012 12:46 PM
Help with touch and timestamps Digjoy83 Shell Programming and Scripting 6 03-16-2012 07:24 AM
Compare 2 timestamps prasannarajesh UNIX for Dummies Questions & Answers 3 03-14-2011 07:57 AM
Compare Timestamps rexpokinghorn Shell Programming and Scripting 2 08-17-2010 09:35 PM
Arithmetic on timestamps balireddy_77 Shell Programming and Scripting 3 03-18-2009 11:02 PM
AWK solution to subtract multiple columns of numbers awkward Shell Programming and Scripting 3 01-18-2009 02:01 PM
timestamps chriss_58 Shell Programming and Scripting 1 05-30-2008 06:12 AM
How to find date Difference in AWK/GAWK with millisecond precision omprasad Shell Programming and Scripting 2 06-06-2006 05:59 AM
Help! Display Time with Millisecond rezlez Programming 3 01-26-2002 12:39 PM