Article 5SAVH Rearrange columns in a csv and do calculations

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?latest?d=yIl2AUoC8zA latest?i=chmdt6DVcwY:HIIOLJnnFz8:F7zBnMy latest?i=chmdt6DVcwY:HIIOLJnnFz8:V_sGLiP latest?d=qj6IDK7rITs latest?i=chmdt6DVcwY:HIIOLJnnFz8:gIN9vFw
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments