title: batch script to print previous and next lines of search string in a text file
body: <p>I have a batch script which will print the entire line of search string into a text file.</p>
  
  <pre><code>for %%i in (log.txt) do (
  FINDSTR /G:pattern.txt %%i &gt;&gt; output.txt
  )
  </code></pre>
  
  <p>Example:
  pattern.txt contains search string <code>ERROR</code> and below is the sample text in log.txt</p>
  
  <pre><code>2013-06-30 02:17:55,562 INFO   Service started
  2013-06-30 02:17:55,578 INFO   Sending mail...
  2013-06-30 02:17:55,578 DEBUG  Element value: 1
  2013-06-30 02:17:55,578 ERROR  error occurred and message is ""
  2013-06-30 02:17:55,578 DEBUG  bit version: 8
  2013-06-30 02:17:55,578 INFO   Service stopped
  </code></pre>
  
  <p>The above batch script will print each line of text whenever it finds the string <code>ERROR</code> in log.txt So, the output.txt will look have lines like below</p>
  
  <pre><code>2013-06-30 02:17:55,578 ERROR  error occurred and message is ""
  </code></pre>
  
  <p>How can I print only previous and next lines of search string like below:</p>
  
  <pre><code>2013-06-30 02:17:55,578 DEBUG  Element value: 1
  2013-06-30 02:17:55,578 DEBUG  bit version: 8
  </code></pre>
  
  <p>Thanks in advance.</p>