12

Shell script to sum every 3 values

view full story
linux-howto

http://www.unix.com – I am looking for an easy way to calculate the sum of three values (*-12, *-01, *-02) which are contained after a comma (,). I have found an awk command that will sum every 3rd value, but I am not interested in the values before the comma (,). Code: awk '{s+=$1}NR%3==0{print s;t+=s;s=0}' I am only interested in summing every 3rd value after the comma (,). If it helps, this 3rd value will contain a -02 in the line. Example: 1944-12,5.6 1945-01,9.8 1945-02,6.7 1945-03,9.3 1945-04,5.9 1945-05,0.7 1945-06,0.0 1945-07,0.0 1945-08,0.0 1945-09,0.0 1945-10,0.2 1945-11,10.5 1945-12,22.3 1946- (HowTos)