Results 1 to 1 of 1
I have been writing an awk script to calculate and report on sales numbers for a couple different files. The only problem i am having is when i try to ...
- 04-26-2009 #1Just Joined!
- Join Date
- Apr 2009
- Posts
- 1
Awk script problem
I have been writing an awk script to calculate and report on sales numbers for a couple different files. The only problem i am having is when i try to call the script.
I want to invoke the script by way of
But so far when ever I do that errors are produced such as:Code:awk -f report products associates sales
When I invoke the script withCode:awk: report:2: awk '/2008/{print $0}' sales > /tmp/newSales awk: report:2: ^ invalid char ' ' ' in expression
It works perfectlyCode:./report products associates sales
Can someone explain to me why this happens and how to go upon converting the file so it works.
Here is the script file
Thank you all who try to help meCode:#! /bin/bash awk '/2008/ {print $0}' sales > /tmp/newSales declare -a names declare -a totalsales declare -a position echo -e "Name:\tPosition:\tTotal Sales:" ID=1 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 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" totalsales[$ID]=$GRANDTOTAL NAMES[$ID]=`awk /^[2]"$ID"/ associates | awk -F"/" '{print $2}'` position[$ID]=`awk /^[2]"$ID"/ associates | awk -F"/" '{print $4}'` echo ${NAMES[$ID]}":"${position[$ID]}":"${totalsales[$ID]} >> /tmp/output.$$ GRANDTOTAL=0 let ID=$ID+1 done sort -n /tmp/output.$$ | awk -F":" '{print $1 $2 $3}' #/tmp/output.$$ # removes all created files rm /tmp/sales.2* rm /tmp/newSales rm /tmp/output.$$


Reply With Quote