0
Host: 1.1.1.1 ()  Ports: 8080/open/tcp//http-proxy/// Ignored State: filtered (28)
Host: 2.2.2.2 ()  Ports: 8888/open/tcp//sun-answerbook/// Ignored State: closed (28)
Host: 3.3.3.3 ()  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

1.1.1.1:8080
2.2.2.2:8888
3.3.3.3:1263
3.3.3.3:1499

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.

0

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
1.1.1.1:8080
2.2.2.2:8888
3.3.3.3:1263
3.3.3.3:1499
3.3.3.3:2301
3.3.3.3:3124
3.3.3.3:3127
3.3.3.3:3128
3.3.3.3:3382
3.3.3.3:4480
3.3.3.3:4816
3.3.3.3:6588
3.3.3.3:7212

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.