Although you should learn how to use RS/FS/OFS -- (as pointed out up-thread) here's a down and dirty way to get around setting RS/FS/OFS (use defaults) -- this is untested and assumes there is only one blank line between groups of records, like this ...
10
20
30
40
50
40
30
20
etc
etc
etc
BEGIN {
while(getline <"data.txt" >0){
if($0 == ""){print sum; sum = 0}
sum+=$0
}
#print sum
#^^^^^^^^
# uncomment this line if the last line in your
# data file is not a blank line.
close("data.txt")
}
It might also be important to point out that AWK is not a one-size-fits-all language nor is it intended to be written once and played everywhere. Each distribution (awk, mawk, gawk, tawk etc) and each platform (linux, unix, win, mac) all have their own personalities and behaviours. It makes it easier to answer an AWK question when the distribution is known. Just a heads up.
Last edited by Rufus T. Firefly; 02-14-2006 at 11:05 AM.
|