title: search in output and cat from specific line to specific line and search again
body: <p>I wrote something like:</p>
  
  <pre><code>OUT=$( nmap -p "$port" --script=http-headers.nse "$ip"
  </code></pre>
  
  <p>for example the output is:</p>
  
  <pre><code>|http-headers: 
  |   Server: Apache
  |   Vary: Accept-Encoding
  |   Content-Type: text/html; charset=utf-8
  |   Date: Thu, 06 Feb 2014 07:31:33 GMT
  |   Age: 25
  |   Connection: close
  </code></pre>
  
  <p>but the length of my output is changeable.
  so I want  something to search between lines in my output (better to use <code>sed</code> or <code>awk</code>)
   and check a condition. for example if it sees <code>Apache</code> from line 3 till line 8 then echo <code>right</code></p>
  
  <p>Edit:</p>
  
  <p>my script:</p>
  
  <pre><code>#!/bin/bash
  
  echo "Reading data - headers - both"
  
  if [ $# -ne 3 ]; then
      echo "Usage: ./nmap &lt;port-range&gt; &lt;ip-list&gt; &lt;d || h || b&gt;"
      exit 1
  fi
  
  if [ $3 == h ]; then
      while read -r -u3 port; do
      while read -r -u4 ip; do
  
  
          echo -n "$ip $port: "
          OUT=$( nmap -p "$port" --script=http-headers.nse "$ip" |
          tail -n 13 | 
          awk -F: '{print $2; exit}')   in other lines
          [[ $OUT == *Apache* ]] &amp;&amp; echo right || echo wrong 
      done 4&lt; "$2"
      done 3&lt; "$1"
  
  elif [ $3 == d ]; then
      echo data
  elif [ $3 == b ]; then 
      echo both
  fi
  </code></pre>
  
  <p>I want to put my right result in file...for example:</p>
  
  <pre><code>cat right.txt
  ip1  port1
  ip2  port2
  
  cat wrong.txt
  ip1 port1
  ip2 port2
  </code></pre>