Advertisement
Guest User

Linux Hw #8

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