Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- awk '
- BEGIN{
- FS=",";
- printf "%-10s\t%-10s\n", "Name", "Average";
- printf "%-10s\t%-10s\n", "----", "-------";
- test_cnt = 0;
- testTotal[1] = testTotal[2] = testTotal[3] = 0;
- }
- NR > 1{
- # getting required columns
- name = $1;
- team = $2;
- first_test = $3;
- second_test = $4;
- third_test = $5;
- # summing and getting average values
- sum_test = first_test + second_test + third_test;
- average = sum_test / 3.0;
- printf "%-10s\t%7.2f\n", name, average;
- # counting the total sum team wise and getting team wise count
- teamTotal[team] += sum_test;
- teamCnt[team] += 3;
- # counting the total test wise
- testTotal[1] += first_test
- testTotal[2] += second_test
- testTotal[3] += third_test
- # counting number of tests
- test_cnt++;
- }
- END{
- printf "%-20s\n", "---------------------------";
- print "Average for Test 1 : ", testTotal[1]/test_cnt;
- print "Average for Test 2 : ", testTotal[2]/test_cnt;
- print "Average for Test 3 : ", testTotal[3]/test_cnt;
- print "----------------------------";
- for (color in teamTotal){
- printf "Average for %s Team: %.2f\n", color, teamTotal[color]/teamCnt[color];
- }
- }' myList.txt
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement