Please excuse my rank newbie status- I'm more used to doing this sort of analysis using excel but given the file sizes I have to deal with AWK seems a better option!
I have telemetry files which I'm trying to summarise into morning, day and evening totals.
The file is 98 columns wide, 23000 rows long and looks like this:
serial number day result1 result2 (...) result 96
I need to aggregate the results by totalling the values in columns 3 to 30, 31 to 78 and 79 to 98 (corresponding to morning, daytime and evening), total the three and do some division. I need an output of
serial number, day, morning, daytime, evening, total, morning/total, daytime/total, evening/total
I thought this was a pretty basic problem so wrote the script below, but I get
awk: syntax error near line 6
awk: illegal statement near line 6
awk: syntax error near line 6
awk: illegal statement near line 6
awk: illegal statement near line 15
If I comment out the third for loop the script runs and I seem to get reasonable results.
Could anyone take a moment to point out where I'm going wrong?
{
for (i=3;i<=30;i++)
morning+=$i
for (i=31;i<=78;i++)
daytime+=$i
for (i=79;i<=98;i++)
evening+=$i
total=morning+daytime+evening
if total>0
print $1,$2,morning*15,daytime*15,evening*15,total*15, morning/total, daytime/total, evening/total, (morning+evening)/total
morning=0
daytime=0
evening=0
total=0
}
Thanks
Mike
I have telemetry files which I'm trying to summarise into morning, day and evening totals.
The file is 98 columns wide, 23000 rows long and looks like this:
serial number day result1 result2 (...) result 96
I need to aggregate the results by totalling the values in columns 3 to 30, 31 to 78 and 79 to 98 (corresponding to morning, daytime and evening), total the three and do some division. I need an output of
serial number, day, morning, daytime, evening, total, morning/total, daytime/total, evening/total
I thought this was a pretty basic problem so wrote the script below, but I get
awk: syntax error near line 6
awk: illegal statement near line 6
awk: syntax error near line 6
awk: illegal statement near line 6
awk: illegal statement near line 15
If I comment out the third for loop the script runs and I seem to get reasonable results.
Could anyone take a moment to point out where I'm going wrong?
{
for (i=3;i<=30;i++)
morning+=$i
for (i=31;i<=78;i++)
daytime+=$i
for (i=79;i<=98;i++)
evening+=$i
total=morning+daytime+evening
if total>0
print $1,$2,morning*15,daytime*15,evening*15,total*15, morning/total, daytime/total, evening/total, (morning+evening)/total
morning=0
daytime=0
evening=0
total=0
}
Thanks
Mike