I'd like to print only the IP address and open ports field from a given a gnmap file.
Host: 123.123.123.123 () Ports: 80/open/tcp//http?///, 443/open/tcp//https?///, 8083/closed/tcp//us-srv///, 65001/closed/tcp///// Ignored State: filtered (65531) Seq Index: 262 IP ID Seq: Randomized Host: 123.123.123.124 () Ports: 80/open/tcp//http?///, 443/open/tcp//https?///, 10443/open/tcp//https///, 65001/closed/tcp///// Ignored State: filtered (65531) Seq Index: 262 IP ID Seq: Randomized Host: 123.123.123.125 () Ports: 80/open/tcp//http?///, 443/open/tcp//https?///, 8083/closed/tcp//us-srv///, 8445/open/tcp//https///, 65001/closed/tcp///// Ignored State: filtered (65531) Seq Index: 262 IP ID Seq: Randomized Host: 123.123.123.126 () Ports: 1337/open/tcp//https?///, 8083/closed/tcp//us-srv///, 65001/closed/tcp///// Ignored State: filtered (65531) Seq Index: 262 IP ID Seq: Randomized
Expected output is
123.123.123.123 80/open/tcp//http?///, 443/open/tcp//https?/// 123.123.123.124 80/open/tcp//http?///, 443/open/tcp//https?///, 10443/open/tcp//https/// 123.123.123.125 80/open/tcp//http?///, 443/open/tcp//https?///
I have already tried a number of different commands, one among which is the below command.
cat targets_osdetection.gnmap | awk '/open/{print $2 " " $5 " "$6 " " $7}'
But it only prints the fields corresponding to the $Number field and since each IP may not have same number of open ports, this command is not so efficient.
Can someone please provide the awk solution for this?
8445/open/tcp//https///
was missed from your 3rd output line. Why?