title: Find & copy a string in a file using only Windows batch
body: <p>I call the file I want to search in <em>input.txt</em> and the string I want to find <em>mystring</em>. </p>
  
  <p>Example content of input.txt <a href="http://pastebin.com/xD8ZCsE3" rel="nofollow noreferrer">(real input.txt)</a></p>
  
  <pre><code>randomstring1&lt;&gt;"\/=:
  randomstring2&lt;ORIGINAL&gt;mystring&lt;/ORIGINAL&gt;randomstring3
  </code></pre>
  
  <ul>
  <li><em>mystring</em> is surrounded by the strings <code>&lt;ORIGINAL&gt;</code> and <code>&lt;/ORIGINAL&gt;</code> that must be  searched for</li>
  <li>The string between both <code>ORIGINAL</code>-tags should be copied to clipboard (using | clip)</li>
  <li><em>mystring</em> and the tags occur only once. But they have no fixed position</li>
  <li>all strings can contain special characters (&lt;, >, ", \, /, =, :)</li>
  </ul>
  
  <p>I read a lot of <a href="https://stackoverflow.com/questions/12973880/windows-batch-script-to-find-string-from-html-file-and-copy-it-to-text-file">other SO questions</a> but to be honest: the FOR-loop and SET-command syntax was too awkward for me. I guess my best shot will be the FINDSTR command. But maybe it is also possible with some help of RegEx expressions.</p>
  
  <p>I do <strong>not</strong> want to use VBscript, Powershell, SED, FART, AWK, grep or any other additional tool. </p>
  
  <p>Please be so kind and explain the difficult parts if you post a solution.<br>
  I want to understand it and maybe its helpful for others too.</p>
  
  <p>My last attempt before I've given up was this <em>test.cmd</em></p>
  
  <pre><code>@echo off
  set "x=randomstring1&lt;&gt;"\/=:randomstring2&lt;ORIGINAL&gt;mystring&lt;/ORIGINAL&gt;randomstring3"
  set "x=%x:*&lt;ORIGINAL&gt;=%"
  set "x=%x:&lt;/ORIGINAL&gt;*=%"
  set  x=%x:~2%
  echo %x%
  pause
  </code></pre>