LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-01-2001, 02:11 AM   #1
cowardnewbie
LQ Newbie
 
Registered: Sep 2001
Location: New York
Posts: 4

Rep: Reputation: 0
Angry Problem with bash script




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
===========================
 
Old 10-01-2001, 06:53 AM   #2
jharris
Senior Member
 
Registered: May 2001
Location: Bristol, UK
Distribution: Slackware, Fedora, RHES
Posts: 2,243

Rep: Reputation: 47
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...
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with bash script. cheater1034 Programming 9 11-21-2005 10:29 PM
bash script problem fatbastard spice Linux - General 2 08-24-2005 02:15 AM
bash script problem GATTACA Programming 3 06-13-2005 09:59 AM
bash script problem sorry99 Programming 2 09-20-2004 09:02 AM
Bash script problem kalleanka Programming 2 01-30-2004 11:59 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:06 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration