I'm fairly new to writing bash and I'm a bit confused on the errors/problem with my code. I have two main problems. In case P)
I would like to see if a certain file exist. If it exist I would like to update the balance
with the newbalance
.
P) read -p "Enter email: " email
read -p "Enter payment amount: " payment
newbalance=$(echo $payment + $balance | bc)
if [ -f $email ]; then
sed -i "s/$balance/$newbalance/" $email
#also tried
#find . -type f -name "$email" -exec sed -i "s/${balance}{newbalance}/" {} \;
else
echo -e "Error: customer not found\n\n"
fi
balance=$newbalance
continue
;;
when I try to read in a payment
such as 100.00
I receive an error:
(standard_in) 2: syntax error
sed: -e expression #1, char 0: no previous regular expression
The file format its self is pretty simple and the balance only appears once.
email name
apt-XX rent balance duedate
The code worked when I redirected echo's to modify the file. Now that I've tried to implement sed
the code has stopped working, I'm unsure of what is causing it. I've tried using find
with sed
but that isn't working either. I've looked at multiple stack overflow questions but the examples are similar to mine.
This is one of the files I'm dealing with
jboat@xyz.com John Boat
APT-5B 1100.00 100.00 2017-10-02