need an awk script/logic

In one data file i have values like this

a b c 1 2
e f g 2 3
i j k 3 5

I need to sum up the last 2 columns and make a data file...How i can do that.

a b c 1 2
e f g 2 3
i j k 3 5
------------------------------------
total 6 10

Please suggest me some ideas.

what have you learned about awk since this thread?

This might be useful....

#!/bin/ksh
lfield=`awk '{ sum+= $NF } END { print sum }' input`
bfield=`awk '{ sum+= $NF-1 } END { print sum }' input`
echo "Total $bfield $lfield "

--Jayan Jayaseelan

How can multiple for loops can be used in awk ?

awk '{ a[name]+=$4} END {for (i in a){print i , a[i]}} ;for (i in b){print i , b
[i]} }' file

I tried this never worked

what are the errors you are getting....? for one, b is not defined anywhere.

awk '{
asum += $(NF-1)
bsum += $NF
{
END{
print ------------------
print "Total " asum" "bsum
}' infile

I need to know how can i implement multiple for loops in awk .

This is the error.

awk: syntax error near line 1
awk: bailing out near line 1

awk '{ a[name]+=$4} END {for (i in a){print i , a}} ;for (i in b){print i , b
} }' file

you have dangling }...instead a[i]}} try a[i]}
and for using b, define it in the same way as you ave done with a.

echo "hi bye cu
> hi1 bye1 cu1
> hi2 bye2 cu2" | awk '{a[$1]=$1;b[$2]=$2} END { for(i in a) print i ; for(j in b) print j}'