Is your file fixed width? If so, a (rather clunky) script could do this:-
#!/bin/ksh
for refs in `cut -d"=" filename | sort -u`
do
tot=0
grep "$refs" filename | while read a b c d value
do
((tot=$tot+$value))
done
print "$refs $tot"
done > newfile
Probaby much neater and more efficient with an awk, but I'm not proficient enough to write them.
Nice method to find the key!
Good, the order doesn't matter!
An attempt to keep the original order makes it more complex and increases memory consumption.
awk '{i=($3<$1?$3" - "$1:$1" - "$3)} !(i in A) {B[NR]=i} {A+=$5}END{for(i=1;i in B;i++) print B" = " A[b]}'
I like sort merge, more robust. I use ksh88+/bash, but I expect awk could do it simpler:
labc= le=0
(
sort foot
echo
) | while read a b c d e
do
abc="$a $b $c"
case "$labc" in
("$abc") # match
(( le += e ))
;;
(?*) # mismatch not blank
echo "$labc = $le"
;& # intentional fall through
(*) # blank = first
labc="$abc" le="$e"
;;
esac
done