Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. awk '
  2. BEGIN{
  3.  
  4. FS=",";
  5. printf "%-10s\t%-10s\n", "Name", "Average";
  6. printf "%-10s\t%-10s\n", "----", "-------";
  7.  
  8. test_cnt = 0;
  9. testTotal[1] = testTotal[2] = testTotal[3] = 0;
  10. }
  11.  
  12. NR > 1{
  13. name = $1;
  14. team = $2;
  15. First_test = $3;
  16. Second_test = $4;
  17. Third_test = $5;
  18.  
  19. total_sum_test = First_test + Second_test + Third_test;
  20. average = total_sum_test / 3.0;
  21. printf "%-10s\t%7.2f\n", name, average;
  22.  
  23.  
  24. teamTotal[team] += total_sum_test;
  25. teamCnt[team] += 3;
  26.  
  27.  
  28. testTotal[1] += first_test
  29. testTotal[2] += second_test
  30. testTotal[3] += third_test
  31.  
  32. test_cnt++;
  33. }
  34. END{
  35. printf "%-20s\n", "---------------------------";
  36. print "Average for Test 1 : ", testTotal[1]/test_cnt;
  37. print "Average for Test 2 : ", testTotal[2]/test_cnt;
  38. print "Average for Test 3 : ", testTotal[3]/test_cnt;
  39. print "----------------------------";
  40. for (color in teamTotal){
  41. printf "Average for %s Team: %.2f\n", color, teamTotal[color]/teamCnt[color];
  42. }
  43.  
  44. }' myList.txt
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement