Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!
-
The problem statement, all variables and given/known data:
The script should compute the sale amounts per associate for the year 2010 and print them in a sorted list ranked according to the sales amount.
Here is an example of the script invocation using the data provided in the example file: % awk -f report inputfile
Lazy Acres, Inc.
2010 Sales Associates Ranking
Name Position Sales Amount
==========================================
Buck, Fast Stock Boy 2630.78
Rush, George Salesman 1049.79
Worker, Susan Manager 360.00
Doe, John Clerk 134.01
Lindon, Rosemary Producer 31.00
Miller, Dennis Comedian 9.902. Relevant commands, code, scripts, algorithms: -
The attempts at a solution (include all code and scripts):
BEGIN {
FS=":"
printf("%s\n", "Lazy Acres, Inc.")
printf("%s\n", "2009 Sales Associates Ranking")
printf("%-25s %-15s %15s\n", "Name", "Position", "Sales amount")
print("=========================================================")
}
# Associates
NF == 3 {
associates[$1] = $2 ":" $3
}
# Products
NF == 4 {
products[$1] = $4;
}
# Sales
NF == 5 && $4 ~ /2010/ {
sales[associates[NF]] = sales[associates[NF]] + ($3 * products[$2])
}
END{
#for loop to print
for (i in sales) {
printf("%15s %41.2f\n", associates, sales) | "sort -nr"
}
}
it prints out the sum of all the sales instead of each individual sale, if I refer to "NF" as "$NF" then it prints out each sale individually but I don't think I'm supposed to do that. Also nothing prints for ''associates[i]" in printf. Any help would be greatly appreciated. I attached the input file also if that helps.
- Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):NIU/Ege/330
Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).