Question

AWK Programming - Please show new working code with screenshot please. Save the following data in...

AWK Programming - Please show new working code with screenshot please.

Save the following data in a file named teamlist.txt:

Name,Team,First Test, Second Test, Third Test Tom,Red,5,17,22
Joe,Green,3,14,22
Maria,Blue,6,18,21

Fred,Blue,2,15,23 Carlos,Red,-1,15,24 Phuong,Green,7,19,21 Enrique,Green,3,16,20 Nancy,Red,9,12,24

Write an AWK script that will compute the average score for every person in the list, the average score for each test, and the average score for each team. If a score is negative, that means the person missed the test, and the score must not become part of the average.

Print the output to look like the following. In the list by name, the names must be left justified in a field of size 10 (hint: %-10s in printf), and the averages must be seven characters wide with two digits to the right of the decimal point (%7.2f).

Name
--------
Tom
Joe
Maria
Fred
Carlos
Phuong 15.67
Enrique 13.00
Nancy 15.00 --------------------------------- Average for Test 1: 5
Average for Test 2: 15.75 Average for Test 3: 22.125 --------------------------------- Average for Red Team: 16 Average for Green Team: 13.8889 Average for Blue Team: 14.1667

Average ------- 14.67 13.00 15.00 13.33 19.50

1

AWK Programming

The Pseudocode

Below is a pseudo-code to help you write the program.

BEGIN{

set FS to a comma

print the header

}

{
if (NR > 1) # this test skips the first line of the file {

Set individualTotal and individualCount to zero

for (field=3; field <=5; field++) {

if ($field >= 0) {

add contents of $field to individualTotal add one to individualCount

# Now update the testTotal and testCount arrays
# subtract 2 from the field number so that our arrays begin at 1 add contents of $field to testTotal indexed by (field-2)
add 1 to testCount array indexed by (field-2)

# Use contents field 2 as the index for the team array

add contents of $field to teamTotal array indexed by $2

add 1 to teamCount array indexed by $2

} }

print the person's name and his individual average

} }

END {
print "------------------" for (n=1; n<=3; n++) {

print average for test n using testTotal and testCount arrays }

print "------------------"

print average for "Red" team
print average for "Green" team
print average for "Blue" team
(these all use the teamTotal and teamCount arrays)

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

format long pa*inv(a) 0 1.00000008068800 Reset the display to the shorter format using format short format affects only the d

Add a comment
Know the answer?
Add Answer to:
AWK Programming - Please show new working code with screenshot please. Save the following data in...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C++ Programming

    PROGRAM DESCRIPTIONIn this project, you have to write a C++ program to keep track of grades of students using structures and files.You are provided a data file named student.dat. Open the file to view it. Keep a backup of this file all the time since you will be editing this file in the program and may lose the content.The file has multiple rows—each row represents a student. The data items are in order: last name, first name including any middle...

  • Lab Objectives Be able to write methods Be able to call methods Be able to declare...

    Lab Objectives Be able to write methods Be able to call methods Be able to declare arrays Be able to fill an array using a loop Be able to access and process data in an array Introduction Methods are commonly used to break a problem down into small manageable pieces. A large task can be broken down into smaller tasks (methods) that contain the details of how to complete that small task. The larger problem is then solved by implementing...

  • CMPS 12B Introduction to Data Structures Programming Assignment 2 In this project, you will write...

    can i get some help with this program CMPS 12B Introduction to Data Structures Programming Assignment 2 In this project, you will write a Java program that uses recursion to find all solutions to the n-Queens problem, for 1 Sns 15. (Students who took CMPS 12A from me worked on an iterative, non-recursive approach to this same problem. You can see it at https://classes.soe.ucsc.edu/cmps012a/Spring l8/pa5.pdf.) Begin by reading the Wikipcdia article on the Eight Queens puzzle at: http://en.wikipedia.org/wiki/Eight queens_puzzle In...

  • Mountain Paths (Part 1) Objectives 2d arrays Store Use Nested Loops Parallel data structures (i.e...

    Mountain Paths (Part 1) in C++ Objectives 2d arrays Store Use Nested Loops Parallel data structures (i.e. parallel arrays … called multiple arrays in the zyBook) Transform data Read from files Write to files structs Code Requirements Start with this code: mtnpathstart.zip Do not modify the function signatures provided. Do not #include or #include Program Flow Read the data into a 2D array Find min and max elevation to correspond to darkest and brightest color, respectively Compute the shade of...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT