awk partial string match and add specific fields

Trying to combine strings that are a partial match to another in $1 (usually below it). If a match is found than the $2 value is added to the $2 value of the match and the $3 value is added to the $3 value of the match. I am not sure how to do this and need some expert help. Thank you :).

file

ACAD11 12 1716
ACAD11;NPHP3-ACAD11 8 1027
ACAD8 10 1395
ACAD9 16 2012
ACAD9;AK125726;KIAA1257 2 214

desired output

ACAD11;NPHP3-ACAD11 20 2743
ACAD8 10 1395
ACAD9;AK125726;KIAA1257 18 2226
awk '
{
   v=$1; sub(";.*", "", v);
   if (!a[v]++ && l) {
      print l ;
   } else {
      $(NF-1)+=b; $(NF)+=c;
   }
   b=$(NF-1); c=$(NF);
   l=$0;
}
END { print $0}
' infile
2 Likes

Thank you very much :slight_smile: