Suppose I have the file FirstDB.txt
and it's populated. With the format
productID:productName:Quantity:Price:DateRegistered
example:
cat FirstDB.txt
0001:Fried Tarantula:15:100:2017-08-27
0002:Wasp Crackers:18:25:2017-08-27
0003:Century Egg:19:50:2017-08-27
0004:Haggis Flesh:20:90:2017-08-27
0005:Balut (Egg):85:15:2017-08-27
then I have a file that is generated by the user named .cart and it's populated as well with the format productID productName Quantity IndividualPrice TotalPrice
cat .cart
0001 Fried Tarantula 5 100 500
0003 Century Egg 7 50 350
0005 Balut (Egg) 6 15 90
I would like to update the FirstDB.txt
product quantity with what the user purchased or selected. Considering the two files that I have above what I would like to happen after is this output:
cat FirstDB.txt
0001:Fried Tarantula:10:100:2017-08-27
0002:Wasp Crackers:18:25:2017-08-27
0003:Century Egg:12:50:2017-08-27
0004:Haggis Flesh:20:90:2017-08-27
0005:Balut (Egg):79:15:2017-08-27
I only have an idea of cutting the first column of .cart
and use grep $(cat .cart)
to get the lines that I need then cut the third column of .cart
to obtain the quantity then subract it to the third column of FirstDB.txt
however it seems like i can't get the output that I want. I'm also thinking of using sed -i
on FirstDB.txt
but haven't tried it yet. Any help? Thank you so much!