2 input files for awk

Hi,
i have 2 files like f1 and f2
f1:
1
Note: some times it will be cahnged to 2 and 3.

f2:
1:20
2:30
4:50
6:70
8:90
3:20
1:30
1:40

output:
1:80
(sum of 1)

for this i wrote awk script.but it's not working.

cat f1.txt | awk '
BEGIN {
FS=":"
load_type=$1;
}

{
number[$1]++;
totaltime[$1]=totaltime[$1]+$2;
}
END {

f ( load_type==1 )
workload="Light_load_avgfile";
else if (load_type==2)
workload="Medium_load_avgfile";
else
workload="Heavy_load_avgfile";

            for\( code in totaltime \)
	\{
	\#calculating avg;
		avg=totaltime[code]/number[code];
		
                            print  code"|"avg "|">workload
			
			\}

}' f2.txt

please help me on this

Another way:

mLoadType=`cat File1`
(echo '0';sed -n "/${mLoadType}:/{s/.*:/+/;p;}" File2 ) | xargs | bc

Is this a typo

it should have been 1 : 90 as per your logic .

another way of doing it in awk !

awk -F":" -v var=`cat f1` '{ a[$1] += $2 }END{ print a[var] }' f2

awk -F":" -v var=`cat f1` '{ a[$1] += $2 }END{ print a[var] }' f2 is not working...
it's display errors
awk: syntax error near line 1
awk: bailing out near line 1

It should work!

which shell are you using ?

awk -F: 'NR==FNR {a[$1]+=$2} NR!=FNR {print $1,":",a[$1]}' f2 f1