This is for an assignment so I have no choice but to use sed.
Given a file messages, how can I extract all the IP addresses and print them?
I first
If you use git-bash on Windows. It is quite handy.
export LC_ALL=C; ipconfig | sed -n 's/IPv4//gp;' | sed -En 's/.*(10.*)/\1/gp'
以太网适配器 VMware Network Adapter VMnet1:
连接特定的 DNS 后缀 . . . . . . . :
本地链接 IPv6 地址. . . . . . . . : fe80::3177:bf7b:590:c787%6
IPv4 地址 . . . . . . . . . . . . : 192.168.31.1
子网掩码 . . . . . . . . . . . . : 255.255.255.0
默认网关. . . . . . . . . . . . . :
以太网适配器 VMware Network Adapter VMnet8:
连接特定的 DNS 后缀 . . . . . . . :
本地链接 IPv6 地址. . . . . . . . : fe80::c8de:747e:34fe:58cd%12
IPv4 地址 . . . . . . . . . . . . : 192.168.239.1
子网掩码 . . . . . . . . . . . . : 255.255.255.0
默认网关. . . . . . . . . . . . . :
以太网适配器 以太网:
连接特定的 DNS 后缀 . . . . . . . : some.com
本地链接 IPv6 地址. . . . . . . . : fe80::9d9:bb4d:e77a:3a98%15
IPv4 地址 . . . . . . . . . . . . : 10.11.68.42
子网掩码 . . . . . . . . . . . . : 255.255.254.0
默认网关. . . . . . . . . . . . . : 10.11.168.1
The script will only give you the 10 prefixed ip address 10.11.68.42.
The script can be explained to be
match lines contain
IPv4and substituteIPv4with blank and print, then capture something prefixed with10and print it