title: Cut and paste a line with an exact match using sed
body: <p>I have a text file (~8 GB). Lets call this file A. File A has about 100,000 lines with 19 words and integers separated by a space. I need to cut several lines from file A and paste them into a new file (file B). The lines should be deleted from file A. The lines to be cut from file A should have an exact matching string.
  I then need to repeat this several times, removing lines from file A with a different matching string every time. Each time, file A is getting smaller.
  I can do this using "sed" but using two commands, like this:</p>
  
  <pre><code># Finding lines in file A with matching string and copying those lines to file B
  sed -ne '/\&lt;matchingString\&gt;/ p' file A &gt; file B
  
  #Again finding the lines in file A with matching string and deleting those lines,
  #writing a tmp file to hold the lines that were not deleted.
  sed '/\&lt;matchingString\&gt;/d'file A &gt; tmp
  
  # Replacing file A with the tmp file.
  mv tmp file A
  </code></pre>
  
  <p>Here is an example of files A and B. I want to extract all lines containing hg15
  File A:</p>
  
  <pre><code>ID pos frac xp mf ...
  23 43210 0.1 2 hg15...
  ...
  ...
  
  File B:
  23 43210 0.1 2 hg15...
  </code></pre>
  
  <p>I´m fairly new to writing shell scripts and using all the Unix tools, but I feel I should be able to do this more elegantly and faster. Can anyone please guide me along to improving this script. I don´t specifically need to use "sed". I have been searching the web and stackoverflow without finding a solution to this exact problem. I´m using RedHat and bash.
  Thanks.</p>