example.csv

Type,LCID,EID,Nx,Ny,Nxy,Mx,My,Mxy,Qyz,Qxz
QUAD,5000001,389635,5.21044,0.9993295,3.184029,0.228490059,0.762438914,0.349926963,0.007402616,0.645762323
QUAD,5000002,389636,4.332321,-45.55149,10.13951,0.128933201,0.289045003,0.442976734,0.394346902,0.965424659
QUAD,5000003,389637,5.332321,-65.55149,12.32391,0.867613103,0.345799842,0.902593358,0.56308979,0.77084519
QUAD,5000004,389638,4.332321,-35.55149,14.27251,0.429855813,0.882431001,0.15453015,0.710809946,0.918974895
QUAD,5000005,389639,5.332455,-75.55149,15.37321,0.738401857,0.289007109,0.59902178,0.824840285,0.571976301
QUAD,5000006,389640,4.332321,-65.55149,13.27221,0.102678011,0.581496802,0.785601755,0.415283869,0.817283531
QUAD,5000007,389641,3.332321,-45.55149,12.67351,0.363658748,0.803570041,0.70688413,0.459446702,0.330453157

ex368.txt

awk 'NR==1{''} NR>1{{ SUM=SUM+$4 }} END { print "Sum=" SUM }' FS=, OFS=, example.csv

output:

Sum=32.2045

ex368.txt

awk 'NR==1{''} NR>1{{ SUM=SUM+$4 }} END {print "Mean=" SUM/(NR-1)}' FS=, OFS=, example.csv

output:

Mean=4.60064

ex368.txt

awk 'BEGIN{print "Line_Number", "Score", "Sum"} NR==1{''} NR>1{{SUM=SUM+$4; print NR, $4, SUM}} END {print "Mean=" SUM/(NR-1)}' FS=, OFS=, example.csv

output:

Line_Number Score Sum
2,5.21044,5.21044
3,4.332321,9.54276
4,5.332321,14.8751
5,4.332321,19.2074
6,5.332455,24.5399
7,4.332321,28.8722
8,3.332321,32.2045
Mean=4.60064

NR>1 to skip the header. If we have missing data points in a form of NA, we need to tell AWK to skip them.
ex368.txt

awk 'NR>1 && $4!="NA"  {{ SUM=SUM+$4 }} END {print "Mean=" SUM/(NR-1)}' FS=, OFS=, example.csv

Discover more from Tips and Hints for Aerospace Engineers

Subscribe now to keep reading and get access to the full archive.

Continue reading