Thursday, November 2, 2023

awk simple 2 col csv sum

awk -F, 'BEGIN { OFS = ","; total = 0; } { if (NR == 1) { print $0; } else { total += $2; lines[NR] = $0; } } END { for (i = 2; i <= NR; i++) { print lines[i]; } print "total," total; }' yourfile.csv > temp.csv && mv temp.csv yourfile.csv

No comments:

Post a Comment