Subtract millisecond Timestamps with awk

Login or Register to Reply

Thread Tools Search this Thread
# 1  
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 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  
Try converting "HH:MM:SS" to seconds. Will the timestamps cross midnight? Month end? Year end?
# 3  
How should I do that? With the date command? The timestamps wont cross midnight, it begins from midnight until
# 4  
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 05:15 PM..
Login or Register to Reply

Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
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...... Shell Programming and Scripting
Shell Programming and Scripting
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...... UNIX for Dummies Questions & Answers
UNIX for Dummies Questions & Answers
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...... Shell Programming and Scripting
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...... Shell Programming and Scripting
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:... Shell Programming and Scripting
Shell Programming and Scripting