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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie problems with multiple 'For' s 1

Status
Not open for further replies.

mikeh1727

Technical User
Mar 9, 2004
3
GB
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 just see missing parenthesis for the 'if' statement
[tt]
{
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;
}
[/tt]

Jean Pierre.
 
I just tried Jean Pierre's suggestion, including the ; terminators which I didn't originally have.

Same errors :+(

Any other thoughts?

Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top