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
Adding multiple column values into single column
Moderators: chulett, rschirm, roy
Adding multiple column values into single column
Regards
LakNar
LakNar
-
- Premium Member
- Posts: 1735
- Joined: Thu Mar 01, 2007 5:44 am
- Location: Troy, MI
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
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
You chose not to mention that when posing the original question.laknar wrote:need to add dynamically
additional columns may be added in future.
Col1 Col1A Col1B Col1C Col1D Col1E
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.
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact: