Home > Mobile >  Ask with awk per lines in ubuntu
Ask with awk per lines in ubuntu

Time:03-22

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

CodePudding user response:

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
  • Related