Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

average block of data

Status
Not open for further replies.

rhnaeco

Technical User
Aug 11, 2005
45
Hi,

I have a file of burst data - i.e. data exists every 0.5 seconds for 1 minute, and then there is a 15 minute gap (approx) before any more data is printed.

Can awk average the data (multiple columns) for each burst and print the line of averaged data to a new file?

Input:
23/11/2008 12:02:39.000 0.001 17.229 0.006 0.010 998.744 1473.540
23/11/2008 12:02:39.500 0.001 17.228 0.006 0.010 998.744 1473.537
23/11/2008 12:17:10.000 0.001 16.993 0.006 0.010 998.785 1472.758
23/11/2008 12:17:10.500 0.001 16.991 0.006 0.010 998.786 1472.751

output:
23/11/2008 12:02 0.001 17.228.5 0.006 0.010 998.744 1473.539
23/11/2008 12:17 0.001 16.992 0.006 0.010 998.785 1472.755


I think the data is consistant, but a 'if' approach may be required.

can anyone help?

thanks

R
 
What have you tried so far and where in your code are you stuck ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
I haven't a clue really! I haven't used awk for a couple of years and so I am almost back to square one. I am currently trying to use the approach of converting the date and time into a number and then using a similar code to
any ideas would be greatly appreciated!

thanks
 
A starting point:
Code:
awk 'function p(){
 if(i>0){printf "%16-16s",x;for(j=3;j<9;++j){printf "%11.4f",a[j]/i;a[j]=0}printf "\n"}
 x=substr($0,1,16);i=0
}
x!=substr($0,1,16){p()}
{for(j=3;j<9;++j)a[j]+=$j;++i}
END{p()}' input > output

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top