title: Editing a text file in linux using sed
body: <p>I have created a script that "simulates" a bank system that allows the user to check their balance and withdraw or deposit money depending on their needs. Details about customer, their balance etc. are saved in a text file named data.txt. When a customer withdraws or deposits money, the text file should be adjusted accordingly. Problem is, using sed like this</p>
  
  <pre><code>sed -i 's/$balance/$($balance + $depositval)/' data.txt 
  </code></pre>
  
  <p>doesn't work. I tried with grep too but no luck either. Is there any way to change the customer's balance to a sum generated from their balance along with the amount of money they wish to deposit (or substract if they need to withdraw money) using sed and passing as argument a variable?</p>
  
  <p>PS: Here are the contents of my data.txt file:</p>
  
  <pre><code>12345 Nick Abrams A 25575
  67890 George Michaels I 10000
  14680 Jack Jordan A 2960
  13670 Michael Patton I 5065
  </code></pre>
  
  <p>The first field is the customer's card number. A and I indicate whether a customer's card is active or inactive. 5th field is balance. BTW i'm using bash shell. Depositval is read from keyboard using read command and balance is found from text file using grep.</p>
  
  <p>For future reference, if somebody needs to do something similar i found out that my first attempt using sed like this</p>
  
  <pre><code>sed -i 's/$balance/$($balance + $depositval)/' data.txt
  </code></pre>
  
  <p>works too, just need to change the ' with "</p>