title: Delete lines before and after a match in bash (with sed or awk)?
body: <p>I'm trying to delete two lines either side of a pattern match from a file full of transactions. Ie. find the match then delete two lines before it, then delete two lines after it and then delete the match. The write this back to the original file.</p>
  
  <p>So the input data is</p>
  
  <pre><code>D28/10/2011
  T-3.48
  PINITIAL BALANCE
  M
  ^
  </code></pre>
  
  <p>and my pattern is</p>
  
  <pre><code>sed -i '/PINITIAL BALANCE/,+2d' test.txt
  </code></pre>
  
  <p>However this is only deleting two lines after the pattern match and then deleting the pattern match. I can't work out any logical way to delete all 5 lines of data from the original file using sed.</p>