Hello, I'm writing a bash script and I have a question.
Here's what I'm doing:
I have a file called inv.dat which contains the following:
Code:
B102:Action Figure - Teacher:79
B103:Bike - Purple:23
B104:Baseball:25
B105:Cricket Bat:15
B101:Action Figure - Fireman:15
B100:Flame-Thrower:25
The Bash script is named manage.bash and here is what it does:
Prompts the user for the item code number. If the Item Number doesn't exist, generate an appropriate error message and terminate your shell script.
Do not ignore case sensitivity when searching for item code number. If the item number exists, extract the item quantity, prompt the user for the amount of items to increase the value in the database.
Heres what running the script looks like:
Code:
[ username ] ./manage.bash
INVENTORY MANAGE MENU
1. Generate Inventory Report
2. Add Item Quantity
Please enter a number (1,2): 2
Enter ITEM #: B106
Does not Exist - Enter ITEM #: B101
Enter units to increase "Action Figure - Fireman": 15
Here is the portion of my script that performs the addition:
Code:
if [[ $TestNum = 2 ]]; then
echo -n "Enter value to increase " && awk -F ":" '$1 == "'"$item"'" {print $2}' inv.dat
read value
awk -F ":" '$1 == "'"$item"'" {OFS = ":"; print $1,$2,'"$value"' + $3 }' inv.dat >> inv.dat
exit
fi
The addition is performed successfully using this script, however when i use the append command, it of course will add the new value to the bottom of the inv.dat file. Is there any way to add the new value and replace the old one? The point of the script is to update the quantity of the item in the database, does anyone have an ideas on how to do this? Would a Sed command help solve this issue?
I would appreciate any suggestions, thanks.