0

I have a scenario where i want to calculate the sum of below data set

V1|V2|V3  
"1.1"|"1.2"|"A"
"1.1"|"1.2"|"B"
"1.1"|"1.2"|"C"

sum of V1 V2 ?

how to that

output :

3.3 3.6 
Kusalananda
  • 333,661

1 Answers1

0
$ cat q
v1|v2|v3
"1.1"|"1.2"|"A"
"1.1"|"1.2"|"B"
"1.1"|"1.2"|"C"
$ sed 's|"||'g q | awk "-F|" \
    'BEG{v1=0;v2=0;}NR>1{v1 = v1 + $1; v2 = v2 + $2;}END{print v1 " " v2}'
3.3 3.6
SYN
  • 2,863
  • its not an effective way to do bro need to parametric so that it can work with any file data like need to take column name V1 V2 V3 in parameter form to script incase in future the requirement may be like 5 column sum is needed then script should be able to calculate 5 column sum ... V1 V2 V3 V4 V5 – genip26057 Jan 02 '20 at 18:35
  • read my solution at the : https://unix.stackexchange.com/questions/559767/how-to-calculate-multiple-floating-point-column-sum ... scroll down till last you will find my solution – genip26057 Jan 02 '20 at 18:37
  • gawk is not awk. Your solution is not portable. Besides, you need bash. Both answers from that thread do. On BSD, that's jut a pain, my answer still stands, while OP did not talk about dynamic columns. – SYN Jan 02 '20 at 20:07