Difference between revisions of "Quick Hacks"

From assela Pathirana
Jump to navigationJump to search
(Created page with '==What is this== These are primarily notes for myself. Things that I often need to do in computing. Instead of keeping them in a private location I list them here. Perhaps someon…')
 
Line 3: Line 3:


==Awk script for accumulating time series data==
==Awk script for accumulating time series data==
<source lang=awk>
<source lang=bash>
#accum.awk
#accum.awk
BEGIN{
BEGIN{

Revision as of 12:53, 22 February 2011

What is this

These are primarily notes for myself. Things that I often need to do in computing. Instead of keeping them in a private location I list them here. Perhaps someone else will also find a use..

Awk script for accumulating time series data

#accum.awk
BEGIN{
    ct=0
     avg=0.0
}
{
 if(++ct%intv==0){
    print x,avg/ct
    ct=0
    avg=0.0
 }else{
    if(ct%intv==1){
        x=$1
    }
    avg+=$2
 }
}

Data:

01/01/1945-00:00 0.0
01/01/1945-01:00 0.0
01/01/1945-02:00 0.0
01/01/1945-03:00 0.0
...

Running:

awk -v intv=24 -f accum.awk  cntr_hly_1.csv.dat