title: Print before and after based on column 1 for the given value from 2nd column
body: <p>Here is what <a href="https://i.stack.imgur.com/2cyac.png" rel="nofollow noreferrer">my CSV file</a> looks like:</p>
  <pre class="lang-none prettyprint-override"><code>1st,2nd ,3rd,4th
  10.1.1.1,10.2.2.2,53,dns
  10.10.10.1,10.20.20.1,80,http
  ,10.20.20.2,443,https
  ,10.20.20.3,80,http
  ,10.20.20.4,443,https
  ,10.20.20.5,80,http
  10.10.10.2,10.30.30.1,22,ssh
  </code></pre>
  <p>I am trying to search for <code>10.20.20.2</code> and get the entire section as shown in the picture:</p>
  <p><a href="https://i.stack.imgur.com/YIM0W.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YIM0W.png" alt="what I am looking for" /></a></p>
  <p>But couldn't figure that out.</p>
  <p>Here is the code what I have so far:</p>
  <pre><code>import re
  import csv
                  
  def csv1():
      with open(&quot;sample.csv&quot;) as search:
          lines = search.readlines()
          m = '10.20.20.2'
          n = '^\d'
          match = False
          
          for line in lines:
              line = line.rstrip()
              if re.search(m, line):
                  match = True
                  print (line)
                  continue
              elif re.match(n, line):
                  match = False
                  continue
              elif match:
                  print (line)
                         
  csv1()
  </code></pre>