LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Problem with bash script (https://www.linuxquestions.org/questions/programming-9/problem-with-bash-script-7087/)

cowardnewbie 10-01-2001 02:11 AM

Problem with bash script
 
:confused:

10/01/01

I have been working on this script for hours without any success.
All I want is to print the total of column 4 and find the average price of that column. Below are my codes and the result that I got.

My data file: (my data filename is called "funny")
Imus McBan: The Waiting game:12-14-2000:24.95
Pat Gruddy:Loose Bowel:07-07-2000:45.95
Kevin Cosner:Seasons of flowers:3-23-2000:6.95
Meat Loaf:Hell On Earth:03-03-1980:11.95
Eddie Money:January Concert:09-04-1979:18.08

script name is: funny_people
My codes:
tput clear
#BEGIN{{FS=":";OFS="\t"} <-------- this code not used
#} not used
# { <-----this code not used
awk -F: '{sum +=$4}' funny_awk
awk -F: '{average=sum/NR}' funny_awk
bold=`tput smso` #setup bold
tput cup 2 20
echo bold
#tput clear #clear whole screen
echo "CD Collection List"
echo $offbold
tput cup 4 20 #row 4, column 20
echo "----------------------------"
tput cup 5 0
echo " Purchase"
echo "Artist CD Name Date Cost"
echo "-------------------------------------------------------------"
awk -F: '{printf "%-15.15s%-25.25s\t%s\t%s\n", $1, $2, $3, $4}' funny_awk
awk '{printf "Total\t$%3.2f", sum}'
awk '{printf "Price Average\t$%3.2f", average}'
echo "End of Script"

The result that I got:

CD Collection List

----------------------------
Purchase
Artist CD Name Date Cost
-------------------------------------------------------------
Imus McBan The Waiting game 12-14-2000 24.95
Pat Gruddy Loose Bowel 07-07-2000 45.95
Kevin Cosner Seasons of flowers 3-23-2000 6.95
Meat Loaf Hell On Earth 03-03-1980 11.95
Eddie Money January Concert 09-04-1979 18.08

This result looks good, but at this point, the program displayed a blank line and I hit the enter key a couple of times and I got the result below endlessly:
Total $0.00
Total $0.00
Total $0.00
Total $0.00
NEED HELP PLEASE =======================
Thank you anybody
===========================

jharris 10-01-2001 06:53 AM

Looks more like a task for Perl to me... Unfortunately I don't have a box with Perl here to be able to help out... Any reason you were using a bash script?

cheers

Jamie...


All times are GMT -5. The time now is 03:37 PM.