Write an awk script that implements a report writer. The report c...

  1. Home
  2. Homework Library
  3. Computer Science
  4. Linux
  5. Write an awk script that implements a report writer. The report c...

QuestionQuestion

Write an awk script that implements a report writer.
The report computes summary data on the performance of sales associates for our company "Lazy Lakes LLC".

The awk script is invoked from the command line with an inputfile that contains data on associates and sales:
awk -f z123456.awk inputfile
The lines in the input file use ":" as field separator and are of either of these 2 kinds:
lines that describe associates have the following fields:
• associate id: an integer number
• name: alphanumeric text
• position: alphanumeric text
lines that describe sales have the following fields:
• transaction id: an integer number
• associate id: an integer number
• zip code: an integer number
• amount: an floating point number with two digits after the decimal point
• date: in the form of yymmdd, ex: 131211 means Dec 11, 2013

The script should compute the sale amounts per associate in zip codes starting with "601" for the year 2013 and print them in a report.
Here is an example of the script invocation using the data provided in the example file:

% awk -f z123456.awk inputfile
Lazy Lakes LLC
2013 Associates Sales Report for Region 601xx
Name             Position    Sales Amount
==========================================
Miller, Dennis    Comedian          84.88
Doe, John         Clerk                   231.93
Worker, Susan    Manager         248.81
Buck, Fast       Stockboy             73.03
Lindon, Rosemary Producer       1603.67
%

Error Checking:
If any error is encountered, such as incorrect data in the input file, just skip the lines in question.
Additional notes:
• The order in which the associates are listed is not significant.
• Make sure that your awk script runs fine on Linux, turing or hopper.
• Make sure that your awk file is a regular Unix text file.

Extra
If you implement this part of the assignment, please indicate it in the file header comment.
Extend the report with 2 more colums:
• sales amount for the year 2012 in the same zip code region "601"
• percentage increase from 2012 to 2013 (show "---" if 2012 sales were 0).
Here is an example of the script invocation using the data provided in the example file:

% awk -f z123456.awk inputfile
Lazy Lakes LLC
2013 Associates Sales Comparison for Region 601xx
Name             Position    Sales 2013    2012 Increase
==========================================================
Miller, Dennis    Comedian         84.88    57.73      47%
Doe, John         Clerk                   231.93    0.00      ---
Rush, George      Salesman         0.00   1050.58    -100%
Worker, Susan    Manager         248.81 3704.43    -93%
Buck, Fast       Stockboy             73.03   492.08    -85%
Lindon, Rosemary Producer       1603.67    0.00      ---
%

Input file:
23:Worker, Susan:Manager
25:Lindon, Rosemary:Producer
21:Doe, John:Clerk
22:Rush, George:Salesman
26:Miller, Dennis:Comedian
24:Buck, Fast:Stockboy
237787:24:60078:106.27:131222
291065:26:60050:59.66:120506
845813:26:60058:44.04:110506
152208:21:60054:57.55:130503
585537:21:60050:38.01:130303
193475:21:60118:30.93:130303
810622:21:60073:188.62:120301
173530:21:60064:187.60:110319
484983:21:60134:46.82:130301
151862:21:60040:28.84:130301
366957:21:60133:154.18:131202
491736:21:60028:175.25:131202
910094:24:60147:9.45:110302
265256:22:60164:1050.58:120302
893187:22:60116:1055.90:110302
220350:24:60155:17.24:130503
631798:24:60171:55.79:130503
571077:24:60201:45.20:120303
332157:24:60095:57.70:120303
104454:24:60175:55.97:120303
# example of erroneous line
502930:24:60058:21.44:110303
567394:24:60052:61.71:120302
854164:24:60120:44.46:120302
040140:24:60163:58.16:120302
108022:24:60061:8.29:120302
639395:24:60161:63.44:120302
013111:24:60122:56.98:120302
720184:24:60074:13.75:110302
101814:24:60109:40.30:110302
482945:24:60113:29.12:110302
254355:24:60027:14.65:120301
676697:24:60099:19.58:120301
896782:23:60126:248.81:130301
759895:23:60074:60.98:130301
720292:23:60075:47.72:110202
907622:24:60207:2415.01:120301
928610:24:60110:2393.22:110301
377662:26:60191:57.73:120503
899755:23:60022:127.26:130523
778879:24:60193:213.07:120303
324254:26:60173:27.23:130303
194231:26:60095:65.31:130303
995552:26:60179:57.65:130302
161296:26:60209:51.31:130302
708034:23:60139:1715.16:120103
501519:23:60104:139.16:120103
936300:25:60051:85.25:120102
716323:23:60166:1850.11:120102
105190:25:60062:60.51:110102
209204:23:60029:2047.19:110102
559396:22:60085:35.44:110102
705432:25:60105:1446.28:130102
078233:25:60143:157.39:130122

Solution PreviewSolution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

#!/bin/awk -f
BEGIN { # begin section
man_count = 0;
year[0] = "12";
year[1] = "13";
FS=":"; # separator
transaction_count = 0;
}
{ # begin program
if(NF == 3){ # associates

   associate_id[man_count] = $1;
   name[man_count] = $2;
   position[man_count] = $3;

   amount[man_count,0] = 0; # 2012...

By purchasing this solution you'll be able to access the following files:
Solution.zip.

$108.00
for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Linux Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats