Adding multiple column values into single column

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
laknar
Participant
Posts: 162
Joined: Thu Apr 26, 2007 5:59 am
Location: Chennai

Adding multiple column values into single column

Post 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
Regards
LakNar
priyadarshikunal
Premium Member
Premium Member
Posts: 1735
Joined: Thu Mar 01, 2007 5:44 am
Location: Troy, MI

Post by priyadarshikunal »

you forgot about '+' operator :?
Priyadarshi Kunal

Genius may have its limitations, but stupidity is not thus handicapped. :wink:
agpt
Participant
Posts: 151
Joined: Sun May 16, 2010 12:53 am

Post by agpt »

use transformer
laknar
Participant
Posts: 162
Joined: Thu Apr 26, 2007 5:59 am
Location: Chennai

Post by laknar »

need to add dynamically

additional columns may be added in future.

Col1 Col1A Col1B Col1C Col1D Col1E
Regards
LakNar
anbu
Premium Member
Premium Member
Posts: 596
Joined: Sat Feb 18, 2006 2:25 am
Location: india

Post by anbu »

Unix solution:

Code: Select all

awk ' { for (i=2;i<=NF;++i){sum+=$i} $NF=$NF FS sum } 1 ' file
You are the creator of your destiny - Swami Vivekananda
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post 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.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
laknar
Participant
Posts: 162
Joined: Thu Apr 26, 2007 5:59 am
Location: Chennai

Post 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.
Regards
LakNar
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

laknar wrote:is there any possibility using Modify stage.
No.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Post Reply