LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 04-23-2009, 08:49 PM   #1
RyudoBlaze
LQ Newbie
 
Registered: Apr 2009
Posts: 4

Rep: Reputation: 0
Help with AWK problem


Hi everyone!

Im new to the forums but was just wondering if someone could help me...

What I ahve is a bash script that has 4 options. The menu is as follows:


MAIN MENU

1. Sales Report
2. Add Sale
3. Add Customer Payment
4. Exit

Enter item number: 2

I'm stuck on add sale and add customer payment. Add sale is the following which is the output of what is entered. The database file is the first argument for the script (so $1)

Enter full customer name: Linus Torvalds
Enter item price: 1
Enter item quantity purchased: 10
Done...

PRESS <ENTER> TO CONTINUE

What I have to do is either two of the following things after Done... is echo'd

1 - Customer is not on file: Just add the customer Name, and total Sales amount at the bottom of the database file.

2 - Customer is already on file: Find the record containing the customer name. Add the existing total sales with new total sales just calculated. Replace the total sales amount for the customer with the newer calculated total sales.

For "Add Customer Payment", the script will prompt the user for a Customer Name and a Total Sales amount. If there is no match of either Customer Name or Total Sales amount, then a message "No Match Found" should be displayed, and wait for the user to press to return to the menu. If there is a match for both Customer Name and Total Sales amount, then the existing total sales is reduced by the payment amount and the new total sales amount is placed in the database file.

I really need help as my AWK isn't that good...

Thankyou!
 
Old 04-23-2009, 09:33 PM   #2
RyudoBlaze
LQ Newbie
 
Registered: Apr 2009
Posts: 4

Original Poster
Rep: Reputation: 0
P.S. the database is as follows

Linus Torvalds:1233
Dan:4212
Christine:3513
 
Old 04-24-2009, 02:01 PM   #3
jan61
Member
 
Registered: Jun 2008
Posts: 235

Rep: Reputation: 47
Moin,

looks like homework for me ;-)

Some hints:
To read and process the database: "awk -F: ' some_awk_commands ' database_file"

To use shell variables in the awk: "awk -v AWK_VAR=$SHELL_VAR ..."

To find a name: "$1 == NAME_VAR { do_something; }"

To add a new line if no matches are found: Set a "found" variable when a line matched, then use the END block of awk to append a line.

Jan

P.S.: Show us, how far you were gone with your script and ask again, if you can't handle a detail.
 
Old 04-24-2009, 07:24 PM   #4
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
Quote:
Originally Posted by RyudoBlaze View Post
[B]I really need help as my AWK isn't that good...
nobody is born to be good at anything in the first place. read, practice, ask and make it good. Here's a good source of AWK for you.
 
  


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
shell command using awk fields inside awk one71 Programming 6 06-26-2008 04:11 PM
AWK problem pppaaarrrkkk Programming 10 02-29-2008 07:29 AM
A problem about awk jackk294 Programming 4 07-13-2006 08:56 PM
AWK problem embsupafly Programming 13 08-21-2005 07:43 PM
awk problem alaios Programming 4 05-04-2003 09:46 AM

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

All times are GMT -5. The time now is 10:53 AM.

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