Quick Hacks

From assela Pathirana
Revision as of 12:52, 22 February 2011 by Root (talk | contribs) (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…')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

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