Skip to main content
Became Hot Network Question
edited tags
Link
αғsнιη
  • 41.9k
  • 17
  • 75
  • 118
deleted 80 characters in body; edited tags
Source Link
αғsнιη
  • 41.9k
  • 17
  • 75
  • 118

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 

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 = income+reward-payment.
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 the way, the names are not unique, so I try (for i) loop to create index for the array [net]. My expected output is:

1 Jackson net = 11000 2 Paul net = 1600 3 Louis net = 3300 

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 = income+reward-payment".

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?

By the way, the names are not unique, so I try (for loop) to create index for the array [net].

My expected output is:

1 Jackson net = 11000 2 Paul net = 3000 3 Louis net = 3300 
added 96 characters in body
Source Link

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 = income+reward-payment.
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 the way, the names are not unique, so I try (for i) loop to create index for the array [net]. My expected output is:

1 Jackson net = 11000 2 Paul net = 1600 3 Louis net = 3300 

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 = income+reward-payment.
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 the way, the names are not unique, so I try (for i) loop to create index for the array [net].

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 = income+reward-payment.
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 the way, the names are not unique, so I try (for i) loop to create index for the array [net]. My expected output is:

1 Jackson net = 11000 2 Paul net = 1600 3 Louis net = 3300 
Source Link
Loading