Book name:author:price:Qty:Qty Sold
==================================
harry potter:james:12.99:197:101
===============================
我想更新 QTY,在这种情况下是 197 的值,但我似乎无法用我的程序更新值,请帮助我,因为我刚刚开始学习 shell 编程。谢谢
function update_qty_available
{
grep -c "$title:$author" BookDB.txt > /dev/null # Look for a line with matching values
if [ $? == 0 ];
then # If found then offer to change Qty
echo "Update Qty to what?"
read newQty
sed -i "s/\($title:$author\):[^:]:[^:]*:/\1:$newQty/" BookDB.txt
echo "Book's Qty has been updated successfully!"
fi