i would like to do a code that prompts user to input the title and author of a book and i want to use grep to get the data based on just the title and author and echo it back for the user to see and edit the price without having the user to enter the old price
I need help in trying to get the $price Variable just by entering the title and author
function update_cost
{
echo "Title: "
read title
echo "Author: "
read author
grep -iqs "$title:$author:$price:" BookDB.txt && echo "$title:$author:$price:"
echo "New Price: "
read price_r
sed -i "/^$title:$author:/ s/$price/$price_r" BookDB.txt || tee BookDB.txt && echo "Book Price has been updated sucessfully!"
}
awk
is better suited to extracting a field from the file and assigning it to a variable.In regards to the question above i came up with an answer for that. Hope it Helps
I manage to get the 3rd field of what the user input by matching it with the result line followed by using the sed line i edited the third field.