2013-12-12 32 views
-2

我得到了与元素的数组:如何用grep特定的字符串,并只显示特定的列

set interfaces ge-1/0/2 unit 108 family inet address 10.187.132.227/27 vrrp-group 8 virtual-address 10.187.132.225 
set interfaces ge-1/0/2 unit 108 family inet address 10.187.132.227/27 vrrp-group 8 priority 200 
set interfaces ge-1/0/2 unit 108 family inet address 10.187.132.227/27 vrrp-group 8 accept-data 
set interfaces ge-1/0/2 unit 109 family inet address 10.187.133.3/27 vrrp-group 9 virtual-address 10.187.133.1 
set interfaces ge-1/0/2 unit 109 family inet address 10.187.133.3/27 vrrp-group 9 priority 190 
set interfaces ge-1/0/2 unit 109 family inet address 10.187.133.3/27 vrrp-group 9 accept-data 
set interfaces ge-1/0/2 unit 110 family inet address 10.187.133.35/27 vrrp-group 10 virtual-address 10.187.133.33 
set interfaces ge-1/0/2 unit 110 family inet address 10.187.133.35/27 vrrp-group 10 priority 200 
set interfaces ge-1/0/2 unit 110 family inet address 10.187.133.35/27 vrrp-group 10 accept-data 
set interfaces ge-1/0/2 unit 111 family inet address 10.187.133.67/27 vrrp-group 11 virtual-address 10.187.133.65 
set interfaces ge-1/0/2 unit 111 family inet address 10.187.133.67/27 vrrp-group 11 priority 190 
set interfaces ge-1/0/2 unit 111 family inet address 10.187.133.67/27 vrrp-group 11 accept-data 
set interfaces ge-1/0/2 unit 112 family inet address 10.187.133.99/27 vrrp-group 12 virtual-address 10.187.133.97 

我怎么用grep地址和VRRP组之间唯一的字符串?

+1

这回答了[这里](http://stackoverflow.com/questions/20550612/perl-grep-with-on-array/20551373#20551373)。 – Kenosis

回答

-1

假定每一行都是一个元素,split空格上的每个元素将它变成一个数组,查看相关数组元素。

1
my @array = ... 

my @strings = map {/address\s*(.*?)\s*vrrp-group/ ? $1 :()} @array; 
相关问题