Rearrange columns in a csv and do calculations
by curiouslinus from LinuxQuestions.org on (#5SAVH)
Hello All,
A newbie here.
I have a need to rearrange a few entries from a csv file and am trying to achieve it using awk or sed.
Input file:
abc,cpu,10
abc,mem,20
abc,disk,10
def,cpu,5
def,mem,10
def,disk,50
xyz,cpu,20
xyz,mem,40
xyz,disk,30
Expected output:
App,cpu,mem,disk
abc,10,20,10
def,5,10,50
xyz,20,40,30
Bal,65,30,10
The Bal is calculated by adding the column values and subtracting by 100.
Any ideas on whats the best way to achieve this?
A newbie here.
I have a need to rearrange a few entries from a csv file and am trying to achieve it using awk or sed.
Input file:
abc,cpu,10
abc,mem,20
abc,disk,10
def,cpu,5
def,mem,10
def,disk,50
xyz,cpu,20
xyz,mem,40
xyz,disk,30
Expected output:
App,cpu,mem,disk
abc,10,20,10
def,5,10,50
xyz,20,40,30
Bal,65,30,10
The Bal is calculated by adding the column values and subtracting by 100.
Any ideas on whats the best way to achieve this?