我想获取google netblock的所有IP。
[root@ip-10-0-7-131 ~]# nslookup -q=TXT _netblocks.google.com 8.8.8.8 | grep 'ip4'
结果如下:
_netblocks.google.com text = "v=spf1 ip4:64.233.160.0/19 ip4:66.102.0.0/20 ip :66.249.80.0/20 ip4:72.14.192.0/18 ip4:74.125.0.0/16 ip4:108.177.8.0/21 ip4:173.194.0.0/16 ip4:209.85.128.0/17 ip4:216.58.192.0/19 ip4:216.239.32.0/19 ~all"
但是我的预期结果是:
64.233.160.0/19
66.102.0.0/20
........
我如何实现我的目标?
我最大的努力就是只获得1个IP:(
[root@ip-10-0-7-131 ~]# nslookup -q=TXT _netblocks.google.com 8.8.8.8 | grep 'ip4' | cut -d: -f3 | awk '{print $1}'
66.102.0.0/20
答案 0 :(得分:1)
使用--perl-regexp
:
$ nslookup -q=TXT _netblocks.google.com 8.8.8.8 | grep -Po 'ip4:\K\S+'
64.233.160.0/19
66.102.0.0/20
66.249.80.0/20
72.14.192.0/18
74.125.0.0/16
108.177.8.0/21
173.194.0.0/16
209.85.128.0/17
216.58.192.0/19
216.239.32.0/19
\K
-放弃之前的比赛[^\s]+
-匹配除空格之外的任何序列答案 1 :(得分:1)
遵循awk
可能会对您有所帮助。
awk '{while(match($0,/[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+\/[0-9]+/)){print substr($0,RSTART,RLENGTH);$0=substr($0,RSTART+RLENGTH+1)}}' Input_file
OR
your_command | awk '{while(match($0,/[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+\/[0-9]+/)){print substr($0,RSTART,RLENGTH);$0=substr($0,RSTART+RLENGTH+1)}}'
答案 2 :(得分:1)
使用GNU awk进行多字符RS,RT和gensub():
echo $value[0]["next_milestone_desc_cur._comp._incl_rltd"];
echo $value[0]["shipment_id"];