title: How to extract binary data from batch file using findstr command?
body: <p>I use the below batch script which has binary part (.exe program) append to the bottom of the script. I used this trick to attach binary part to my batch script:</p>
  
  <pre><code>::Append binary part to your batch file with COPY
  copy /y /a "batchscript.bat" + /b program.exe /b combined.bat
  </code></pre>
  
  <p>In order to extract the binary part from the batch script (combined.bat), I use the following method with "findstr" command:</p>
  
  <pre><code>;;;===,,, @ECHO OFF
  ;;;===,,, SETLOCAL ENABLEEXTENSIONS
  ;;;===,,, 
  ;;;===,,, echo test line1
  ;;;===,,, echo test line2
  ;;;===,,, 
  ;;;===,,, findstr /v "^;;;===,,," %~f0 &gt; program.exe
  ;;;===,,, 
  ;;;===,,, echo test line3
  ;;;===,,, echo test line4
  ;;;===,,, exit /b
  ;;;===,,, ::Below are binary data for program.exe
  binarybinarybinarybinarybinarybinarybinarybinarybinarybinarybinarybinary
  binarybinarybinarybinarybinarybinarybinarybinarybinarybinarybinarybinary
  ...
  </code></pre>
  
  <p>So this piece of code extracts the binary part from the script to program.exe:</p>
  
  <pre><code>findstr /v "^;;;===,,," %~f0 &gt; program.exe
  </code></pre>
  
  <p>But as a down-side, each line of the script part must begin with following prefix</p>
  
  <pre><code>;;;===,,,
  </code></pre>
  
  <p>What I want to do is to use the prefix ";;;===,,," only at the last line of code and extract all binary data after this line. Is it possible to achieve this via some crazy combination of findstr + for loop + if command? Example:</p>
  
  <pre><code>@ECHO OFF
  SETLOCAL ENABLEEXTENSIONS
  
  echo test line1
  echo test line2
  
  HERE IS THE CODE TO EXTRACT BINARY PART AFTER LAST SCRIPT LINE
  
  echo test line3
  echo test line4
  exit /b
  ;;;===,,, ::Below are binary data for program.exe
  binarybinarybinarybinarybinarybinarybinarybinarybinarybinarybinarybinary
  binarybinarybinarybinarybinarybinarybinarybinarybinarybinarybinarybinary
  ...
  </code></pre>
  
  <p>Many thanks in advance.</p>