ramsiri@blake.acs.washington.edu (Enartloc Nhoj) (12/25/89)
I grabbed awk.ttp from the net many months back..
and have used it successfully for string matching
and manipulation...
Last night i wrote a couple of quick dot.g scripts
in gulam using awk to produce some quick reports
for my student records which included integer addition.
The scripts are very straight forward with a simple loop.
I am not sure if the problem is in the conditional or what.
Here are the two awk scripts:
due.awk
-------
BEGIN { FS = "\t"
printf("%-15s %4s \n\n", "STUDENT", "DUE")
}
{ printf("%-15s %4d \n", $1, $2)
total = total + $2
}
END { printf("\n-%15s %4d \n", "TOTAL DUE" , total) }
owe.awk
-------
BEGIN { FS = "\t"
printf("%-15s %4s \n\n", "STUDENT", "OWED") }
{
if ( $2 > $3 ) {
printf("%-15s %4d\n", $1, $2 - $3 )
total = total + ($2 - $3)
}
}
END { printf("\n%-15s %4d \n", "TOTAL DUE", total) }
If I pass a file such as this to the awk scripts:
Abdul 125 0 15 60 weird
Nadily 100 0 15 72 gorgeous
Mark 125 0 15 12 no comment
....
etc
Where field $2 is the amount DUE and $3 is amount PAID...
I should get the same results with both due.awk and owe.awk.
On the ST, owe.awk yields a total that is greater by
a value equal to the first line $2 field. I inserted
print statements to find the error.. I thought i was
not understanding the way awk searches for patterns on
a line by line basis... but when i uploaded it to BSD..
it worked straight forward and gave correct results.
IS there a problem(s) with AWK.TTP , or am i misunderstanding
something in my code? I'd much rather be able to write
short dot.g scripts for quick things like this than have
to compile C code or open a spread sheet etc..
Thanks ..
-kevin
ramsiri@blake.acs.washington.edu