'Ask with awk per lines in ubuntu
I am testing how to add with some lists and I was thinking how to make a cumulative list per line, I understand that I can add a whole line and indicate the number of rows to add:
awk '{l+=$1}NR%6==0{print l;l=0}' file
Numbers | Sum per line
1 | 1
2 | 3
4 | 7
0 | 7
0 | 7
7 | 14
Solution 1:[1]
With your shown samples, please try following awk code.
awk '
BEGIN{
OFS=" | "
print "Numbers","Sum per line"
}
{
$0=prev?($0 OFS prev+$1):($0 OFS $1)
prev+=$1
}
1
' Input_file
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
