I am trying to create an awk script to subtract milliseconds between two entries, for example:
At the command line, I can do this:
Input:
06:20:00.120 06:20:00.361 06:20:15.205 06:20:15.431 06:20:35.073 06:20:36.190 06:20:59.604 06:21:00.514 06:21:25.145 06:21:26.125
Command:
awk '{ if ( ( NR % 2 ) == 0 ) { printf("%s\n",$0) } else { printf("%s ",$0) } }' input
I will get this:
06:20:00.120 06:20:00.361 06:20:15.205 06:20:15.431 06:20:35.073 06:20:36.190 06:20:59.604 06:21:00.514 06:21:25.145 06:21:26.125
To subtract milliseconds correctly:
awk '{ if ( ( NR % 2 ) == 0 ) { printf("%s\n",$0) } else { printf("%s ",$0) } }' input| awk -F':| ' '{print $3, $6}'
And to avoid negative numbers:
awk '{if ($2<$1) sub(/00/, "60",$2); print $0}' awk '{$3=($2-$1); print $3}'
The goal is to get the following:
Call 1 0.241 ms Call 2 0.226 ms Call 3 1.117 ms Call 4 0.91 ms Call 5 0.98 ms
And finally, the middle one.
I could accomplish this, but command by command. I do not know how to place this in a script.
Please, help.
source share