Conditional aggregation and print of a column in file

Hi
My input file looks like

field1 field2 field3 field4 field5
field1 field2 field3 field4 field5
field1 field2 field3 field4 field5
::::::::::::
::::::::::::

There may be one space of multiple spaces between fields and no fields contains spaces in them.

If field 1 to 4 are equal for consecutive rows sum field 5 and continue this until any field is different.If any field in different, print field 1 to 4 and the sum.

I tried with following code and working perfectly:

Bu for input file of 70000 lines it takes 5 mins.
Can this be improved?? Please help

      first_rec=1
      while read line
      do
         if [[ $first_rec -eq 1 ]]
         then
            field1=`echo $line|tr -s " "|cut -d" " -f1`
            field2=`echo $line|tr -s " "|cut -d" " -f2`
            field3=`echo $line|tr -s " "|cut -d" " -f3`
            field4=`echo $line|tr -s " "|cut -d" " -f4`
            field5=0
            first_rec=0
         fi
         new_field1=`echo $line|tr -s " "|cut -d" " -f1`
         new_field2=`echo $line|tr -s " "|cut -d" " -f2`
         new_field3=`echo $line|tr -s " "|cut -d" " -f3`
         new_field4=`echo $line|tr -s " "|cut -d" " -f4`
         new_field5=`echo $line|tr -s " "|cut -d" " -f5`
         if [ fields 1 -4 are same ]
         then
            field5=`echo $field5 + $new_field5|bc` #Float field
         else
            echo "$field1$field2$field3$field4$field5" >> output file
            field5=$new_field5
         fi
         field1=$new_field1
         field2=$new_field2
         field3=$new_field3
         field4=$new_field4
      done < Input_file
      # for last record
      echo "$field1$field2$field3$field4$field5" >> output file

Try:

awk '{ str=$1" "$2" "$3" "$4; if (arr[str]== "") arr[str]=$5; else arr[str]+=$5; } END { for (x in arr) print x" "arr[x]; }' file

input:

output:

Hi dennis

Brilliant command..
Suppose if the input is fixed length like

field1<1 space>field2<3 spaces>field3<5spaces>field4<10 spaces>field5

where spaces can vary..
I need output in same format as input just the field 5 will change value.
I need output in format printf "%-20s%-10s%-10s%-10s%10s"

Please help

try this. But am concerned about the speed of execution now...

awk '{ str=$1" "$2" "$3" "$4; if (arr[str]== "") arr[str]=$5; else arr[str]+=$5; } END { for (x in arr) { str=x" "arr[x]"\n"; split(str,a," ");printf "%-20s%-10s%-10s%-10s%10s\n", a[1],a[2],a[3],a[4],a[5]; }}'  file