bash - Shell reading IP addresses from file -


i have long file

feb  2 18:43:05 os sshd[14786]: [id 800047 auth.info] connection closed 2001:778:200:4280::37 feb  2 18:46:08 os sshd[14788]: [id 800047 auth.info] connection closed 158.129.0.37 feb  2 18:48:05 os sshd[14790]: [id 800047 auth.info] connection closed 2001:778:200:4280::37 feb  2 18:48:29 os sshd[14791]: [id 800047 auth.info] did not receive identification string 61.240.144.64 feb  2 19:46:08 os sshd[14853]: [id 800047 auth.info] connection closed 158.129.0.37 feb  2 19:48:05 os sshd[14855]: [id 800047 auth.info] connection closed 2001:778:200:4280::37 feb  2 20:21:42 os sshd[14892]: [id 800047 auth.info] accepted keyboard-interactive evakaz 2001:778:200:4001:e076:812f:23e7:7e62 port 47889 ssh2 feb  2 21:20:19 os sshd[14960]: [id 800047 auth.info] received disconnect 2001:778:200:4280::38: 11: disconnected user feb  2 21:21:08 os sshd[14963]: [id 800047 auth.info] connection closed 158.129.0.37 feb  2 22:31:01 os sshd[15100]: [id 800047 auth.info] received disconnect  222.161.4.149: 11: ... ... 

and in each line there ip adress. possible read ip adresses (not entire file) in shell?

for ipv4:

$ grep -woe '([[:digit:]]+\.){3}[[:digit:]]+' file 158.129.0.37 61.240.144.64 158.129.0.37 158.129.0.37 222.161.4.149 

for ipv6:

$ grep -oe '([[:xdigit:]]+:){7}[[:xdigit:]]+' file 2001:778:200:4001:e076:812f:23e7:7e62 

for both:

$ grep -oe '([[:xdigit:]]+:){7}[[:xdigit:]]+|([[:digit:]]+\.){3}[[:digit:]]+' file 158.129.0.37 61.240.144.64 158.129.0.37 2001:778:200:4001:e076:812f:23e7:7e62 158.129.0.37 222.161.4.149 

Comments

Popular posts from this blog

c++ - No viable overloaded operator for references a map -

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - Cannot secure connection using TLS -