Make a countdown column with awk
by Drosera_capensis from LinuxQuestions.org on (#55XDV)
Hello everyone,
A little question about awk.
Given a column of numbers in a "list" file.
0
1
2
3
4
5
I wish to print a list displaying (sum - value) at each row, as a countdown of the sum of the first list.
15
13
10
6
1
0
I have tried to set up a script to do it, but it does not work.
Code:cat list | awk ' BEGIN {S+=$1} END {a=$1} {print (S-$a)}'Would anyone has a solution for this?


A little question about awk.
Given a column of numbers in a "list" file.
0
1
2
3
4
5
I wish to print a list displaying (sum - value) at each row, as a countdown of the sum of the first list.
15
13
10
6
1
0
I have tried to set up a script to do it, but it does not work.
Code:cat list | awk ' BEGIN {S+=$1} END {a=$1} {print (S-$a)}'Would anyone has a solution for this?