Compute in milisecond by use of mktime


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Compute in milisecond by use of mktime
# 8  
Old 06-18-2013
I have responded here to random_thoughts on how to calculate with milliseconds using mktime and awk

https://www.unix.com/shell-programmin...ent-lines.html
# 9  
Old 06-19-2013
Nope I used split to compute in milisecond. anyways thanks

---------- Post updated at 10:11 AM ---------- Previous update was at 10:09 AM ----------

Thanks Jotne!
# 10  
Old 06-19-2013
Here is what i had in mind...
Code:
awk '{
   n = split($NF, a, ",")
   g = "(....)-(..)-(..) (..):(..):(..),.*$"
   f = "\\1 \\2 \\3 \\4 \\5 \\6"
   d[NR] = gensub(g, f, "", $(NF-1)" "$NF)
   t = mktime(d[NR])
   d[NR] = t * 1000 + a[n]
} END {
   print NR
   for (i=1; i<NR; i+=2)
       print "diff: " d[i+1] - d[i]
}' file

where file contents are...
Code:
$ cat file
Starttime 2013-04-03 08:54:19,989
End time  2013-04-03 08:54:39,389

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Compute value from more than three consecutive rows

Hello all, I am working on a file like below: site Date time value1 value2 0023 2014-01-01 00:00 32.0 23.7 0023 2014-01-01 01:00 38.0 29.9 0023 2014-01-01 02:00 85.0 26.6 0023 2014-01-01 03:00 34.0 25.3 0023 2014-01-01 04:00 37.0 23.8 0023 2014-01-01 05:00 80.0 20.3 0023 2014-01-01 06:00... (16 Replies)
Discussion started by: kathy wang
16 Replies

2. UNIX for Beginners Questions & Answers

Forward Display from compute node

Hello, sorry if this is an easy thing, but I tried to make it run the whole morning, but it doesn't work so far... I am logged in on a visualization node of a high performance cluster. On this node I can run several gui-based software for the postprocessing of my cfd-data. As the... (1 Reply)
Discussion started by: Shlaeae
1 Replies

3. Shell Programming and Scripting

awk mktime(strftime(format,"6-FEB-2013 08:50:03.841")

I'm trying to use AWK to filter on some dates in a field by converting them to Unix Time. mktime(strftime(format,"6-FEB-2013 08:50:03.841")What is the proper format for my date strings as they appear in my database? My first thought is %d-%b-%Y %H:%M:%Sbut I see the following issues: %d is... (3 Replies)
Discussion started by: Michael Stora
3 Replies

4. UNIX for Advanced & Expert Users

[SOLVED] Making mktime/strftime available to mawk

I frequently use awk time functions and am switching some scripts over to mawk. I don't have the mktime or strftime functions in mawk, but it appears that there is a way, as explained here in "Time functions": Please only cut-and-past links to man pages from our man pages. So, simple... (10 Replies)
Discussion started by: treesloth
10 Replies

5. Shell Programming and Scripting

Compute Difference and Edit second, third columns

Hi Friends, My input file is like this chr1 100 200 chr1 300 330 chr1 2000 2000 chr1 5000 5000 chr2 7790 7890 chr2 8000 8000 If the difference of third and second columns is zero, then subtract 500 from second column and add 500 to the third column. So, my output would be chr1... (1 Reply)
Discussion started by: jacobs.smith
1 Replies

6. Web Development

How to compute previous and next buttons?

I have a project to migrate my club's membership database from Access to web based using MySQL/PHP, but I have a problem I can't get my head around and would appreciate some help... Background... I want to be able to display each member's data on screen and add a Previous and Next button to move... (2 Replies)
Discussion started by: JerryHone
2 Replies

7. Shell Programming and Scripting

Compute difference between 2 arrays perl

Hi, I have 2 arrays. I have to compute symmetric difference! @arr=qw(19205134 18630215 18453487 18416242 18338715 18227590 17698645); @arr1=qw(18227590 18053561 17698645 16966777); #The code which i used is this! @union = @isect = @diff = (); %union = %isect = (); %count =... (3 Replies)
Discussion started by: vanitham
3 Replies

8. Shell Programming and Scripting

compute compilation time using script

Hi, I use this script to compute compilation time several time to get system performance and compare different system: #!/bin/sh # measure the different between time before and # after the compilation of benchmark # Start at iteration 1 num=1 while do # Add one to the iteration... (3 Replies)
Discussion started by: zainab
3 Replies

9. Shell Programming and Scripting

to compute diskspace

Guys, have any idea for the script like this? also to compute w/ decimal. thanks a=10 b=20 c=30 d=40 if a < b then ( a -b)*1024 = free space b + (c -d) = total space if a > b then (b / d)*1024 = cpu (3 Replies)
Discussion started by: kenshinhimura
3 Replies

10. Shell Programming and Scripting

compute total from a text file

Hi, I've encountered a problem with a perl and ksh script that totals a certain field in a text file. The computed total of the script is 295540304 but the expected is 297959288, a 2 million difference. The KSH script reads from bottom to top, and the discrepancy started on line 47 (1279th MAN... (1 Reply)
Discussion started by: rsf01
1 Replies
Login or Register to Ask a Question