Thanks for the reply... i have been working on a similar script as the one you wrote out for me... and i have it pretty much working minus 2 things (pretty much)...
I am working now on getting the names from the associate file to store into an array such as:
Code:
NAMES[$ID]=`awk -F"/" '{print $2}' associates`
But as i found out that will go through associates and store ALL names into the array.
Is there a way around this - for it to take line one, find the name ($2), store into [1], take line two, find the name ($2), store into [2], and so on....?
Here is my script (please note there may be variations of the above code in multiple places, this is me trying to find the right place, until i realized that it just wont work the way i have coded the line)...
The idea is that if i can get the names into an array[1-6] so that
($ID = 1)
${NAMES[$ID]} = "John Doe"
($ID = 2)
${NAMES[$ID]} = "George Bush"
etc...
I could then move on and do similar thing for their respective job titles (obviously it will be same thing but different array name).
Then i can just use a while loop such as:
Code:
ID=1
while [ "$ID" -le 6 ]
do
echo "${NAMES[$ID]} ${POSITION[$ID]} ${TOTALSALES[$ID]}"
ID=$ID+1
done
So if i could get a hand how i can handle and store the names into an array, that would be awesome - if i get it before someone posts, ill edit the post accordingly, thanks guys.
***************EDIT****************
You need to see my entire code?
Code:
#! /bin/bash
awk '/2007/ {print $0}' sales > /tmp/newSales
#cat /tmp/newSales
ID=1
NAMES=()
while [ $ID -le 6 ]
do
awk /[2][$ID]$/ /tmp/newSales > /tmp/sales.2$ID
let ID=$ID+1
done
GRANDTOTAL=0
ID=1
while [ $ID -le 6 ]
do
echo "SALES FOR ASSOCIATE 2$ID"
while read line
do
PRODID=`echo $line|cut -d"," -f1`
QUANT=`echo $line|cut -d"," -f2`
PRICE=`awk /^$PRODID/ products|awk -F":" '{print $3}'`
TOTAL=$(echo "scale=2; $PRICE*$QUANT" | bc)
GRANDTOTAL=$(echo "scale=2; $GRANDTOTAL+$TOTAL" | bc)
done < "/tmp/sales.2$ID"
# NAMES[$ID]=`awk -F"/" '{print $2}' associates`
# echo "NAME[$ID]: ${NAMES[$ID]}"
echo Grand total for 2$ID: $GRANDTOTAL
GRANDTOTAL=0
let ID=$ID+1
done
#NAME[1]=`awk -F"/" '{print $2' associates`
#echo new names array : ${NAMES[1]}
ID=1
#while ["$ID" -le 6]
# do
# echo "2$ID ${NAMES[$ID]} TOTAL (LATER )"
# ((ID+=1))
# done
# removes all created files
rm /tmp/sales.2*
rm /tmp/newSales
A run of the script produces:
/home/lx/z109079 : ./newtest.sh
SALES FOR ASSOCIATE 21
Grand total for 21: 284.74
SALES FOR ASSOCIATE 22
Grand total for 22: 1059.67
SALES FOR ASSOCIATE 23
Grand total for 23: 279.52
SALES FOR ASSOCIATE 24
Grand total for 24: 2504.83
SALES FOR ASSOCIATE 25
Grand total for 25: 151.00
SALES FOR ASSOCIATE 26
Grand total for 26: 1.98