Hey guys - i am working off three files that contain information on associates and their sales.
The files are:
products: (product ID, name, price item)
% cat products
103:sway bar:49.99
101ropeller:104.99
104:fishing line:0.99
...
108:wheel:49.99
111:lock:31.00
102:trailer hitch:97.95
sales: (product ID,num. sold, date sale, associate ID)
% cat sales
110,1,01:02:2007,22
110,2,02:02:2007,23
109,1,03:03:2006,24
104,2,03:02:2007,24
...
104,2,05:03:2007,24
112,1,05:03:2007,23
104,9,05:03:2007,21
associates: (associate ID, name, salary, position)
% cat associates
21/John Doe/39000/Clerk
22/George Bush/99000/President
23/Susan Worker/44000/Manager
24/Fast Buck/21000/Stock Boy
25/Hillary Clinton/99000/Candidate
26/Dennis Miller/88000/Commedian
The output needs to come out something like:
$ ./report.sh
Name Position Sales Amount
========================================
Fast Buck Stock Boy 2712.77
George Bush President 1059.67
Susan Worker Manager 399.52
John Doe Clerk 284.74
Hillary Clinton Candidate 151.00
Dennis Miller Commedian 2.97
command line command: ./report.sh
I have done the following to start -
#! /bin/bash
awk '/2007/ {print $0}' sales > /tmp/newSales.$$
COUNTER=21
while [ $COUNTER -le 26 ]
do
awk '$1 == $COUNTER {print $0}' /tmp/newSales.$$ > /tmp/sales.$COUNTER.$$
echo "SALES FOR ASSOCIATE $COUNTER"
cat /tmp/sales.$COUNTER.$$
let COUNTER=$COUNTER+1
done
#Below removes all created files
rm /tmp.newSales.$$
i=21
while [ $i -le 26 ]
do
rm /tmp/sales.$COUNTER.$$
let i=$i+1
done
As i hope you can see - what i want to do is to go through each associate (numbered 21-26) and take their sales and store it into their own sales file.
The first line i have makes sure that ONLY sales from 2007 are now in the sales file i will be working with ... does this make sense so far?
Is there a reason why the files though would end up being empty? Is there something i am overlooking? Thanks guys...