05-08-2008
HELP PLEASE!! school assignment due in two hours!!
The assignment is worth 100 points.
Write a shell script that implements a report writer. The script file should be called "report" and should be invocable as
report
from the command line. In your script you may use common Unix commands: make sure that your script runs fine on lx.cs.niu.edu.
The script uses 3 data files -- called "products", "sales", "associates" -- as described below:
products: has the following fields, the field separator is ":"
* product id: an integer number
* description: alphanumeric text
* price: floating point number, with 2 significant digits
sales: has the following fields, the field separator is ","
* product id: an integer number
* quantity: an integer number
* date: in the form of dd:mm:yyyy
* associate id: an integer number
associates: has the following fields, the field separator is "/"
* associate id: an integer number
* name: alphanumeric text
* salary: an integer number
* position: alphanumeric text
(click here to see examples of these files.)
The script should compute the sale amounts per associate for the year 2008 and print them in a list ranked according to the sales amount. Your script should invoke Unix commands on the above files to produce a report on standard output. Here is an example of the script invocation using the data provided in the example files above:
$ ./report
Marine Parts R US
2008 Sales Associates Ranking
Name Position Sales Amount
========================================
Fast Buck Stock Boy 2408.87
George Bush President 1059.67
Susan Worker Manager 139.76
John Doe Clerk 134.01
Hillary Clinton Candidate 31.00
$
Make sure that your script repors any error, such as problems with the input files, and that all temporary files are removed once the script ends.
I HAVE NO IDEA HOW TO GET THIS TO WORK, I HAVE GOTTEN SOME CODE DOWN BUT IT GETS STUCK ON ONE PART. HERES MY CODE, SOMEONE PLEASE HELP ME!!!!
#! /bin/bash
awk '/2007/ {print $0}' sales > /tmp/newSales.$$
#wc -l /tmp/newSales.$$ | cut -c1-2 > $LINES
LINES=`wc -l /tmp/newSales.$$ | cut -c1-2`
echo lines in file $LINES
COUNTER=21
while [ $COUNTER -le 26 ]
do
COUNT=1
while [ $COUNT -lt $LINES ]
do
awk '$4 == $COUNTER {print $0}' /tmp/newSales.$$ >> /tmp/sales.$COUNTER.$$
let COUNT=$COUNT+1
done
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
I THINK THE PROBLEM IS IN.....
awk '$4 == $COUNTER {print $0}' /tmp/newSales.$$ >> /tmp/sales.$COUNTER.$$
5 More Discussions You Might Find Interesting
1. IP Networking
I'm in highschool. They blocked my favorite site. How do I disable websense without getting caught on that particular webpage? Is it even possible? *twitch* I would also like to get as much UNIX for beginners information, so if someone might point me in the right direction so I don't have to read... (1 Reply)
Discussion started by: Satine
1 Replies
2. AIX
Whats up ppl...
I'm at a loss here.. Getting help with old versions of AIX is quite stressful lol...
Anyways.. My situation is that I (my company) has an old Powerserver 220 running AIX 3.2.5.
The server is about to crap out, and we need to move the system over to a newer box.
I've... (3 Replies)
Discussion started by: NOTORIOUS VR
3 Replies
3. OS X (Apple)
i have really no administrative privileges at my school
how can i add my self to passwd and create a root account? (6 Replies)
Discussion started by: shanepowell
6 Replies
4. Shell Programming and Scripting
Hi, I have assignment from school. Please help me write the script for following example
Using "eval", write a program called "recho" that prints its arguments in reverse order.
For example,
$recho one two three
should produce
three two one (1 Reply)
Discussion started by: sdp5628
1 Replies
5. Shell Programming and Scripting
Hi Frens,
I want to list some files from a directory, which contains "DONE" in their name, i am receiving files every minute. In this i want to list all the files which are newer than 6 hours but older than 3 hours, of current time
i dont want my list to contain the latest files which are ... (4 Replies)
Discussion started by: Prat007
4 Replies
times(1) User Commands times(1)
NAME
times - shell built-in function to report time usages of the current shell
SYNOPSIS
sh
times
ksh
times
DESCRIPTION
sh
Print the accumulated user and system times for processes run from the shell.
ksh
Print the accumulated user and system times for the shell and for processes run from the shell.
On this man page, ksh(1) commands that are preceded by one or two * (asterisks) are treated specially in the following ways:
1. Variable assignment lists preceding the command remain in effect when the command completes.
2. I/O redirections are processed after variable assignments.
3. Errors cause a script that contains them to abort.
4. Words, following a command preceded by ** that are in the format of a variable assignment, are expanded with the same rules as a vari-
able assignment. This means that tilde substitution is performed after the = sign and word splitting and file name generation are not
performed.
ATTRIBUTES
See attributes(5) for descriptions of the following attributes:
+-----------------------------+-----------------------------+
| ATTRIBUTE TYPE | ATTRIBUTE VALUE |
+-----------------------------+-----------------------------+
|Availability |SUNWcsu |
+-----------------------------+-----------------------------+
SEE ALSO
ksh(1), sh(1), time(1), attributes(5)
SunOS 5.10 15 Apr 1994 times(1)