The command to summarize the 2nd column of the csv file

Hi, I have a csv file that has 2 coloumns columns, has names, and secons has values. All I want is a script that can sum the values โ€‹โ€‹of the second column and output the output in the last line of csv as Total

Example file: -

CNG 2128485188 WND 222047363 HUM 283010928 AINGO 253694944 

The command I'm using is printing on the last line, but the total amount is 0.

 $ awk '{print;s+=$2}END{printf "Total %'\''d\n",s}' /cygdrive/c/KPI/test/SCCP_ADMIN_RAW2.csv | tail -10 LIMIT,27789 VDEOT,21109 CELZA,627 DUUNI,26636 EMBLT,1255927 URA,521 MONTE,1789 EGLMO,391 DGTEL,394 Total 0 
+6
source share
1 answer
 $ awk -F"," '{print;x+=$2}END{print "Total " x}' ./test.csv CNG ,1 WND ,2 HUM ,1 AINGO ,1 Total 5 
+10
source

Source: https://habr.com/ru/post/953428/


All Articles