linux - Extract only ip addresses from a txt file an put them into a line -


i have txt file full of traceroutes , on form.

traceroute 188.164.206.1 (188.164.206.1), 30 hops max, 60 byte packets

 1  83.212.10.1 (83.212.10.1)  3.257 ms  4.571 ms *   2  192.168.199.1 (192.168.199.1)  5.497 ms  3.171 ms  5.537 ms   3  ihu-1-gw.eier.access-link.grnet.gr (194.177.208.13)  11.188 ms  13.018 ms  11.305 ms   4  wind.gr-ix.gr (176.126.38.9)  14.421 ms  12.267 ms  14.714 ms 

traceroute 194.39.121.182 (194.39.121.182), 30 hops max, 60 byte packets

1 ec2-50-112-0-84.us-west-2.compute.amazonaws.com (50.112.0.84) 2.026 ms 1.986 ms 1.969 ms

2 100.64.1.149 (100.64.1.149) 1.757 ms 100.64.1.171 (100.64.1.171) 2.006 ms 100.64.1.157 (100.64.1.157) 2.772 ms

3 * * *

4 * * *

5 205.251.232.226 (205.251.232.226) 2.324 ms 205.251.232.166 (205.251.232.166) 2.332 ms 205.251.232.226 (205.251.232.226) 2.988 ms

im trying make script read lines of file , copy ip adreses inside (...) , transfer them 1 line. every traceroute 1 line. example above traceroute become

83.212.10.1 192.168.199.1 194.177.208.13 176.126.38.9 

i can not think obvious ways on how this, in advance.

this should want.

awk -f'[()]' '/^ / {printf "%s ", $2}' 

using standard value fs:

awk '/^ / {gsub(/[()]/, "", $3); printf "%s ", $3}' 

or not using regex @ all:

awk '/^ / {printf "%s ", substr($3, 2, (length($3) - 2))}' 

edit: handle multiple traceroute output in same file correctly.

awk -f'[()]' '/^ / {printf "%s ", $2; next} /^[^[:space:]]/{print ""}' 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -

django - CSRF verification failed. Request aborted. CSRF cookie not set -