Summing the columns of a file

Hi All,

I have a file like -

num.txt

12, 34, 65, line1
34, 65, 89, line2
43, 65, 77, line3

I want to do two things -

  1. Add first three columns of each line and print the line with largest value.
    i.e. (12+34+65) for 1st line and so on.
  2. Add middle column of each line i.e. (34+65+65) and print the result.

Can this be done without writing a script? I mean just through collection of pipelines commands?

Thanks in advance
-asahlot

This smells like a homework question. Assuming that it's not, what are you working on?

Regards

Well, this question was asked by my friend and I think he was asked in some interview. Neither he nor me could solve and I just thought of posting it here. We can solve it by writing a script but didnt get the concept of w/o script.

You can use awk to solve this problem

awk '{s+=$2; a=$1+$2+$3;if(a > b){l=$0;b=a}}END{printf "%s\n%s\n",l,s}' file