title: Move lines matching a pattern from one file to another
body: <p>I want to move lines matching certain pattern from <em>file1</em> to <em>file2</em>. Analogous to operation <em>cut and paste from one file to another</em> in windows</p>
  
  <p><strong>Example</strong></p>
  
  <p>let's say I want to cut all lines containg <code>bar</code> from <em>file1</em> and paste it into newly created <em>file2</em></p>
  
  <p>Input:</p>
  
  <p>file1</p>
  
  <pre><code>bla foo bla
  bla bar bla
  bla aaa bla
  bla bar bla
  bla foo bla
  </code></pre>
  
  <p>Desired output after processing:</p>
  
  <p>file1</p>
  
  <pre><code>bla foo bla
  bla aaa bla
  bla foo bla
  </code></pre>
  
  <p>file2</p>
  
  <pre><code>bla bar bla
  bla bar bla
  </code></pre>
  
  <p><strong>What I have tried</strong></p>
  
  <p><code>grep</code> creates desired <em>file2</em> but doesn't modify <em>file1</em></p>
  
  <pre><code>grep 'bar' file1 &gt; file2
  </code></pre>
  
  <p><code>sed -i</code> modifies desired <em>file1</em> but doesn't create <em>file2</em></p>
  
  <pre><code>sed -i '/bar/d' file1
  </code></pre>
  
  <p>If I execute both commands one after another, I get desired result. But here I am looking for a <strong>single line command</strong> out of curiosity and to make a script more concise.</p>
  
  <p>Your help would be appreciated.</p>