peopleperson88
Technical User
I'm attempting to create a database for an ATM project that I'm working on.
Here is what I have so far.
A script called nawk.test. This file is used to find the member's number and then subtract the amount given from their current balance, then publish the results.
I need to be able to 1) find the balance, 2) calculate
the new balance (old balance - withdraw amount) and 3) substitute it back into the database.
I can get #1 and #2 - but cannot get the statement to
publish the new value correctly back into the database.
Here is how I am executing the script.
nawk.test 111111 50
[script][member number][withdrawl amount]
MEM=$1
FIELD=10
old_balance=`nawk ' BEGIN { FS = ":" } /^'$1'/ { print $10 } ' data_base`
new_balance=`expr $old_balance - $2`
nawk -F: -v field=$FIELD change=$new_balance ' $1 ~ /$MEM/ {$field=change;OFS=":";print $0} ' data_base >> data_base2
echo $old_balance
echo $new_balance
Here is the database that I am working with.
File name is database.
[Member Number][Fname][MI][LName][Address][ST][Zip][Balance][Last Amount][Last Type (withdrawl, deposit, etc..)]
11111:BOB:JONES:9909 Hoyt Way:Westminster:CO:80021:CHECKING:5000:200
22222:CHARLES:AETERS:1800 Test Street:Carter Lake:CO:80052:CHECKING:20000:50:W
33333:MARY:X:SMITH:1234 Wadsworth Blvd:Broomfield:CO:80021:CHECKING:10000:200:W
Someone plesae help me. I have been working on this for a very long time and can NOT figure this one out.
Thanks
Here is what I have so far.
A script called nawk.test. This file is used to find the member's number and then subtract the amount given from their current balance, then publish the results.
I need to be able to 1) find the balance, 2) calculate
the new balance (old balance - withdraw amount) and 3) substitute it back into the database.
I can get #1 and #2 - but cannot get the statement to
publish the new value correctly back into the database.
Here is how I am executing the script.
nawk.test 111111 50
[script][member number][withdrawl amount]
MEM=$1
FIELD=10
old_balance=`nawk ' BEGIN { FS = ":" } /^'$1'/ { print $10 } ' data_base`
new_balance=`expr $old_balance - $2`
nawk -F: -v field=$FIELD change=$new_balance ' $1 ~ /$MEM/ {$field=change;OFS=":";print $0} ' data_base >> data_base2
echo $old_balance
echo $new_balance
Here is the database that I am working with.
File name is database.
[Member Number][Fname][MI][LName][Address][ST][Zip][Balance][Last Amount][Last Type (withdrawl, deposit, etc..)]
11111:BOB:JONES:9909 Hoyt Way:Westminster:CO:80021:CHECKING:5000:200
22222:CHARLES:AETERS:1800 Test Street:Carter Lake:CO:80052:CHECKING:20000:50:W
33333:MARY:X:SMITH:1234 Wadsworth Blvd:Broomfield:CO:80021:CHECKING:10000:200:W
Someone plesae help me. I have been working on this for a very long time and can NOT figure this one out.
Thanks