Average of multiple time-stamped data every half hour

Hi All,

Thank you for reading through my post and helping me figure out how I would be able to perform this task.

For example: I have a list of continuous output collected into a file in the format as seen below:

 Date...........Time........C....A......... B
==========================
"2014-10-13 15:45:00",0,-1.92925,-0.529
"2014-10-13 15:45:00.1",1,-2.0245,-0.65
"2014-10-13 15:45:00.2",2,-2.0245,-0.65

The first two values are date and time (in hh:mm:ss:millisecond , every 10ms =1 second), the third value (C) doesnt really matter, and the last two values are the numbers lets say A and B. Could you please suggest me, how I would be able to calculate the average every half an hour. If possible I would like to store the values to another file once the averages are calculated.

For example the average of values A from 15:45:00 to 16:14:59:9

Thank you for your suggestions.

Regards,
Terry

Even though you edited your post for clarity, your request is both confusing and ambiguous.

Is this a homework assignment?

What have you tried to solve your problem?

A millisecond is .001 second; 10ms is not 1 second; 10ms is .01 second.

What average are you trying to calculate (the average of the A values and the average of the B values, the average of the sums of the A and B values, the average of the A and B values)?

1 Like

Hi Don,

Thanks a lot for your reply.

Regarding your question, if this is a homework assignment, it's not. I collect a stream of data and use excel to take an average since I am not a programmer or someone with Unix background. Maybe it's about time I can learn some perl etc. and make my life a little easier than having to use excel to take an average.

Like you said, I was wrong in saying the last item on the value for time is millisecond. It actually goes from 0 till 9 for the next value and then the value for second increases by one.

Also, I am trying to calculate average of A values and average of B values for the duration of 30 minutes.

Regards,
Terry

If you have GNU awk try this:

awk -F, '
{
 split($0,T,"\"");
 gsub("[-:]", " ", T[2])
 split(T[2],V,".")
 D=mktime(V[1])
 if(D>B) {
    if(C) print "\"" strftime("%Y-%m-%d %H:%M:%S",B) "\"", sumA/C, sumB/C
    B=D+30*60
    sumA=sumB=C=0
 }
 C++
 sumA=sumA+$3
 sumB=sumB+$4
}
END {if(C) print "\"" strftime("%Y-%m-%d %H:%M:%S",B) "\"", sumA/C, sumB/C}' OFS=, infile
1 Like

Many thanks Chubler_XL.

Now, I am trying to figure out how I can have access to GNU awk and I will keep you updated regarding how I come across it.

Regards,
Terry

If you have perl already then it should be pretty simple to solve this problem...

1 Like