Sure thing:
sales is the initial sales file
associates is the associates file
SRep is the script
sales2 and assoc are the same files hand typed with the ":" separator. I don't/haven't tried that with the script - but instead run a manual join and they work fine.
Thanks for the help
umm - I selected upload, but the files did not "Attach" hmm well here is a cut and paste of the files:
sales (partial):
104,2,03:07:2004,24
104,3,03:07:2004,24
113,92,12:07:2004,24
104,2,03:07:2004,24
104,1,03:07:2004,26
104,2,03:07:2004,24
112,1,01:07:2004,23
104,9,03:08:2004,21
105,2,03:08:2004,24
111,4,12:07:2004,21
106,2,03:07:2004,24
107,9,03:08:2004,21
108,21,03:07:2004,22
109,12,03:08:2004,24
110,2,03:08:2004,23
104,2,03:07:2004,24
104,2,03:09:2004,24
104,1,03:09:2004,26
104,2,03:09:2004,24
112,1,01:09:2004,23
104,9,03:09:2004,21
104,2,05:09:2004,24
104,1,05:09:2004,26
104,2,05:09:2004,24
112,1,05:09:2004,23
104,9,05:09:2004,21
Associates:
21/John Doe/39000/Clerk
22/Kirk Russell/99000/President
23/Susan Smith/44000/Manager
24/Fast Buck/21000/Stock Boy
25/Scott Brown/99000/Engineer
26/Aimee Woods/88000/Secretary
script SRep:
#!/bin/bash
#=============================================================
# Script: Sales Report - Assignment 2
# Date: February 2005
# Purpose:
#trap " rm t[1] 2>/dev/null; exit" 0
awk '
BEGIN {
{ FS = ":"}
{ print "\t Marine Parts R US\n" }
{ print "\t Sales Associates Ranking\n" }
{ "date" | getline d }
{ printf "\t %s\n",d }
}'
# Select the September sales
awk '/:09:/ { print $0 }' sales > sept
echo "============== September Sales ============"
# cat sept
# Strip the dates since we don't need them anymore
# the sort the file on the ID field
cut -d, -f1,2,4 sept > sept_wo_dates
sort -t, -k 3 < sept_wo_dates -o sept_sort
# cat sept_sort
# make the sales file have a : separator
sed -n 's/,/:/gp' < sept_sort > sept_colon
cat sept_colon
# make the associates file have a consistent : seperator
sed -n 's/[/]/:/gp' < associates > assoc_colon
cat assoc_colon
# join the two files
join -t: -1 3 -2 1 -o 1.1 -o 1.2 -o 2.2 -o 2.4 sept_colon assoc_colon > sept_assoc
cat sept_assoc
the hand made files:
sales2 (partial)
109:1:03:09:2004:24
104:2:03:07:2004:24
104:3:03:07:2004:24
113:92:12:07:2004:24
104:2:03:07:2004:24
104:1:03:07:2004:26
104:2:03:07:2004:24
112:1:01:07:2004:23
104:9:03:08:2004:21
105:2:03:08:2004:24
111:4:12:07:2004:21
106:2:03:07:2004:24
107:9:03:08:2004:21
108:21:03:07:2004:22
assoc:
21:John Doe:39000:Clerk
22:Kirk Russell:99000:President
23:Susan Smith:44000:Manager
24:Fast Buck:21000:Stock Boy
25:Scott Brown:99000:Engineer
26:Aimee Woods:88000:Secretary