title: In-place edits with sed on OS X
body: <p>I'd like edit a file with sed on OS X.  I'm using the following command:</p>
  
  <pre><code>sed 's/oldword/newword/' file.txt
  </code></pre>
  
  <p>The output is sent to the terminal.  <strong>file.txt</strong> is not modified.  The changes are saved to <strong>file2.txt</strong> with this command:</p>
  
  <pre><code>sed 's/oldword/newword/' file1.txt &gt; file2.txt
  </code></pre>
  
  <p>However I don't want another file.  I just want to edit <strong>file1.txt</strong>.  How can I do this?</p>
  
  <p>I've tried the -i flag.  This results in the following error:</p>
  
  <pre><code>sed: 1: "file1.txt": invalid command code f
  </code></pre>