Host: ()  Ports: 8080/open/tcp//http-proxy/// Ignored State: filtered (28)
Host: ()  Ports: 8888/open/tcp//sun-answerbook/// Ignored State: closed (28)
Host: ()  Ports: 1263/open/tcp/////, 1499/open/tcp//fhc///, 2301/open/tcp//compaqdiag///, 3124/open/tcp/////, 3127/open/tcp/////, 3128/open/tcp//squid-http///, 3382/open/tcp/////, 4480/open/tcp//proxy-plus///, 4816/open/tcp/////, 6588/open/tcp//analogx///, 7212/open/tcp/////, 8000/open/tcp//http-alt///, 8080/open/tcp//http-proxy/// Ignored State: closed (4)

Desired output would be

I know how to handle it if there was 1:1 ratio of IP to ports, but there can be multiple ports open for a single IP. I've just been grepping the output from the file with an appropriate regex for each part and putting it in an array, is there an easier way of doing things? My text manipulation skills in nix are very rudimentary.


You seem to have missed some lines in your desired output... Try running through the fields from the fifth, checking for a numeric start, split by / and print the first element along with $2:

awk '{for (i=5; i<=NF; i++) if ($i ~ /^[0-9]/) {split ($i, T, "/"); print $2 ":" T[1]}}' file

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.