Average marks from list

后端 未结 3 1792
北海茫月
北海茫月 2020-12-11 12:13

Sorry if I don\'t write good, it\'s my first post.

I have a list in one file with the name, id, marks etc of students (see below):

And I want to calculate th

3条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-11 12:41

    awk 'NR>1{n=split($NF,a,",");for(i=1;i<=n;i++){s+=a[i]} ;print $1,s/n;s=0}' input
    athos 3.875
    porthos 3.5
    aramis 3
    

    For all the lines except header(NR>1 will filter out header) , pick up the last column and split into smaller numbers by comma. Using for loop sum the value of all the marks and then divid by the total subject number.

提交回复
热议问题