This is another post of the same code I've posted before with a different slant and some more verbage below it:
I'm attempting to run the following script from p.68 of the Aho, Kernighan, Weinberger bible:
{ for (i=1; i <=NF; i++)
sum += $i
if (NF > maxfld)
maxfld = NF
}
END { for (i = 1; i <= maxfld; i++) {
printf("%g", sum)
if (i < maxfld)
printf("\t"
else
printf("\n"
}
}
My data (which I cannot post because it is sensitive data) is 8 columns of double-precision, 32-bit words. The data had a 9th column which was time in HH:MM:SS but since I didn't know how to handle this in Awk I printed out the remaining fields to a file and piped the file to the code above (which I call ex31_input) as input. I have some time on my hands at the moment so I can probably create a sample data file to post as well; I'll try to post the sample file in a day or two.
Forgetting the index value for sum (should be sum, as it is above) may have caused my code to return nothing. It is supposed to return nothing if the input file is empty; it obviously is not empty. Anyhow, assuming that I fix the sum to read sum, how can I make this script run for any number of numeric fields (8 in my example with a time stamp as the first field = 9 fields total) with the first field is in HH:MM:SS?
Thanks for everybody's help with my other posts - they are my first to this board. I keep the responses in an Awk notebook so if I go a few months without having to use Awk (which can happen in my line of work) I have a reference to go back to.
I'm attempting to run the following script from p.68 of the Aho, Kernighan, Weinberger bible:
{ for (i=1; i <=NF; i++)
sum += $i
if (NF > maxfld)
maxfld = NF
}
END { for (i = 1; i <= maxfld; i++) {
printf("%g", sum)
if (i < maxfld)
printf("\t"
else
printf("\n"
}
}
My data (which I cannot post because it is sensitive data) is 8 columns of double-precision, 32-bit words. The data had a 9th column which was time in HH:MM:SS but since I didn't know how to handle this in Awk I printed out the remaining fields to a file and piped the file to the code above (which I call ex31_input) as input. I have some time on my hands at the moment so I can probably create a sample data file to post as well; I'll try to post the sample file in a day or two.
Forgetting the index value for sum (should be sum, as it is above) may have caused my code to return nothing. It is supposed to return nothing if the input file is empty; it obviously is not empty. Anyhow, assuming that I fix the sum to read sum, how can I make this script run for any number of numeric fields (8 in my example with a time stamp as the first field = 9 fields total) with the first field is in HH:MM:SS?
Thanks for everybody's help with my other posts - they are my first to this board. I keep the responses in an Awk notebook so if I go a few months without having to use Awk (which can happen in my line of work) I have a reference to go back to.