title: How to grep specific lines from nmap -O output?
body: <p>I got many files named like <code>192.168.203.txt</code> as the output of </p>
  
  <pre><code>sudo nmap -O --top-ports 192.168.203.* &gt;&gt;192.168.203.txt 
  </code></pre>
  
  <p>The output looks like as below: </p>
  
  <pre>
  <code>
  Nmap scan report for 192.168.203.29
  Host is up (0.00067s latency).
  PORT     STATE    SERVICE
  21/tcp   closed   ftp
  22/tcp   closed   ssh
  23/tcp   closed   telnet
  25/tcp   closed   smtp
  80/tcp   open     http
  110/tcp  closed   pop3
  139/tcp  filtered netbios-ssn
  443/tcp  closed   https
  445/tcp  filtered microsoft-ds
  3389/tcp filtered ms-wbt-server
  Device type: general purpose
  Running: Microsoft Windows 2008|7
  OS CPE: cpe:/o:microsoft:windows_server_2008::sp2 cpe:/o:microsoft:windows_7
  OS details: Microsoft Windows Server 2008 SP2, Microsoft Windows 7 or Windows Server 2008 SP1
  Network Distance: 6 hops
  </code>
  </pre>
  
  <p>I just want to grep the IP like <code>192.168.203.29</code> with <code>http</code> or <code>ssh</code> or other ports  <code>open</code> sepetately. Maybe I will pipe all the result <code>IP</code> into a file named <code>http_open_ip.txt</code>.  </p>
  
  <p>I have tried grep <code>ftp</code> with commands:</p>
  
  <pre><code>cat *.txt|grep -B 3 "ftp"|grep -B3 "open"|grep "192.168."|awk '{print $5}'|sort -t . -k 3,3n -k  4,4n&gt; ftp_open_ip.txt
  </code></pre>
  
  <p>Thus, I got a file <code>ftp_open_ip.txt</code>. But I found this command  not work with other keywords like <code>ssh</code> <code>stmp</code>. What should I do ? </p>