title: Using grep and sed to find and replace a string
body: <p>I am using the following to search a directory recursively for specific string and replace it with another:</p>
  
  <pre><code>grep -rl oldstr path | xargs sed -i 's/oldstr/newstr/g'
  </code></pre>
  
  <p>This works okay. The only problem is that if the string doesn't exist then <code>sed</code> fails because it doesn't get any arguments. This is a problem for me since i'm running this automatically with ANT and the build fails since <code>sed</code> fails.</p>
  
  <p>Is there a way to make it fail-proof in case the string is not found?</p>
  
  <p>I'm interested in a one line simple solution I can use (not necessarily with <code>grep</code> or <code>sed</code> but with common unix commands like these).</p>