I had a csv file of data such like that when read into shell:
name,income,reward,payment Jackson,10000,2000,1000 Paul,2500,700,200 Louis,5000,100,1800 and I want to find the net earning for each person, use formula: net"net = income+reward-paymentpayment".
when
when I used command to do this, it only calculate the first row of data.
$ cat data.csv | awk -F ',' '{for (i=1;i<=NF;i++) net[i] = $2+$3-$4} END {for (p in total) print p, "net = ", net[p]}' > result.txt How can I do the calculation here? I think the loop doesn't work well but I'm new to it, I don't figure it out clearly.
By
By the way, the names are not unique, so I try (for i) loop) to create index for the array [net]. My
My expected output is:
1 Jackson net = 11000 2 Paul net = 16003000 3 Louis net = 3300