title: Replace only if string exists in current line
body: <p>I have a line such as:</p>
  
  <pre><code>sed -i 's/mystring/newstring/' $target
  </code></pre>
  
  <p>This command will change all <code>mystring</code> to <code>newstring</code>.</p>
  
  <p>What I want now is: when the program sees <code>mystring</code>, how can I check for the current line if the string <code>searchstring</code> exists or not? If it exists, <code>newstring</code> is <code>1</code>; otherwise, <code>newstring</code> is <code>0</code>.</p>