title: Parsing nmap output
body: <p>A project to familiarize myself that I'm working on is to parse through an <code>nmap</code> result.</p>
  
  <p>(I know of the <code>-oG</code> option, but I'm working with <code>grep</code>, <code>awk</code>, <code>for</code>, and <code>while</code> loops here).</p>
  
  <p>Below is what I'm trying to parse through:</p>
  
  <pre><code>Starting Nmap 7.60 ( https://nmap.org ) at 2017-12-05 11:26 EST
  Nmap scan report for house.router.nick (192.168.1.1)
  
  
  Host is up (0.00059s latency).
  Not shown: 995 closed ports
  PORT     STATE SERVICE
  22/tcp   open  ssh
  53/tcp   open  domain
  427/tcp  open  svrloc
  1900/tcp open  upnp
  
  MAC Address: 50:C7:BF:A8:CF:C8 (Tp-link Technologies)
  
  
  Nmap scan report for 192.168.1.2
  
  
  Host is up (0.00034s latency).
  Not shown: 996 closed ports
  PORT      STATE SERVICE
  22/tcp    open  ssh
  80/tcp    open  http
  139/tcp   open  netbios-ssn
  445/tcp   open  microsoft-ds
  
  MAC Address: 48:F8:B3:C9:AE:BB (Cisco-Linksys)
  </code></pre>
  
  <p>What I want to get is this:</p>
  
  <pre><code>22/ssh
  ====
  192.168.1.1
  192.168.1.2
  
  http
  ===
  192.168.1.2
  </code></pre>
  
  <p>So far, I have this:</p>
  
  <pre><code>grep -E "tcp.*open" nmap.txt | awk '{ print $3 }' | sort | uniq
  </code></pre>
  
  <p>For the life of me, I can't figure out how to get this into a loop of sorts and get the desired output from above. </p>
  
  <p>Can you please help me learn and explain why you came to the solution you did? No point in getting a potential solution if I can't understand the logic behind it.</p>