#!/bin/awk -f # Lists open ports coming from nmap. # It assumes the file is in PYX format and complies with the appropriate DTD. function reset() { protocol = ""; portid = 0; state = "" service = ""; in_port = 0; } BEGIN { reset(); } /\(port$/ { in_port = 1; } /\)port$/ { printf("%s %u %s %s\n", protocol, portid, state, service); reset(); } /^Aprotocol / { if (in_port) protocol = $2; } /^Aportid / { if (in_port) portid = $2; } /^Astate / { if (in_port) state = $2; } /^Aname / { if (in_port) service = $2; }