Page 1 of 1

Adding multiple column values into single column

Posted: Tue Jun 15, 2010 11:14 am
by laknar
i have below input

Col1 Col1A Col1B Col1C

ABC 10 10 10

CDE 10 10 10

EFG 10 10 10

Need output like below

Col1 Col1A Col1B Col1C Col1_SUM

ABC 10 10 10 30

CDE 10 60 10 80

EFG 10 20 10 40

Posted: Tue Jun 15, 2010 11:27 am
by priyadarshikunal
you forgot about '+' operator :?

Posted: Tue Jun 15, 2010 11:28 am
by agpt
use transformer

Posted: Tue Jun 15, 2010 11:35 am
by laknar
need to add dynamically

additional columns may be added in future.

Col1 Col1A Col1B Col1C Col1D Col1E

Posted: Tue Jun 15, 2010 12:34 pm
by anbu
Unix solution:

Code: Select all

awk ' { for (i=2;i<=NF;++i){sum+=$i} $NF=$NF FS sum } 1 ' file

Posted: Tue Jun 15, 2010 4:53 pm
by ray.wurlod
laknar wrote:need to add dynamically

additional columns may be added in future.

Col1 Col1A Col1B Col1C Col1D Col1E
You chose not to mention that when posing the original question.

There is a delightfully elegant solution using a server job or a BASIC Transformer stage, where you treat all of the numeric fields as a dynamic array and apply a Sum() or Summation() function thereto.

Posted: Fri Jun 18, 2010 9:01 am
by laknar
is there any possibility using Modify stage.
But the columns should not be hard coded.
suppose if i want to sum 100 columns(existing columns) and introduce a new column for the output value.

how can i do this in Schema file and RCP scenario.

Posted: Fri Jun 18, 2010 4:51 pm
by ray.wurlod
laknar wrote:is there any possibility using Modify stage.
No.