title: How to replace text in a existing file using script on linux?
body: <p>I want to replace <code>abc</code> with <code>XYZ</code>, for which have written below script in a file named <code>test.sh</code>; the file is executed on terminal with <code>sh test.sh</code> command </p>
  
  <pre><code>i='abc';
  </code></pre>
  
  <p>Command:</p>
  
  <pre><code>perl -pi -e 's/$i/XZY/g' /home/user/Desktop/file.txt
  </code></pre>
  
  <p>gedit file.txt</p>
  
  <p>But the output is:</p>
  
  <pre><code>XYZaXYZbXYZc
  XYZ
  </code></pre>
  
  <p>Can't able to figure out the problem.</p>