I am doing a update on the file test.txt which stores some info about storybooks
I've the code below for the function but i realise that using this method of grep, i am unable to get the rest of the values for price quantity and sold which are not mentioned in the grep command.
Is there a better command i can use for this case?
Thanks in advance for replies. :)
echo "Title: "
read title
echo ""
echo "Author: "
read author
echo ""
echo "Number of copies sold: "
read numSold
if grep -iq "$title:$author:" test.txt
then
echo "Current Book Info :"
echo "$title, $author, $price, $quantity, $sold"
echo ""
newQuantity=`expr $quantity - $numSold`
newSold=`expr $sold + $numSold`
sed -i "s/^\($title:$author:[^:]*\):[^:]*:/\1:$newQuantity:/" BookDB.txt
sed -i "s/^\($title:$author:.*\):.*$/\1:$newSold/" BookDB.txt
echo "New Book Info :"
echo "$title, $author, $price, $quantity, $sold"
fi