Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to search an array?

Status
Not open for further replies.

lynxus

ISP
Oct 24, 2006
10
GB
Hi Guys,

I have a script that connects to cisco kit and runs a show ip int brief.

It gives me info like this in an array:
Interface IP-Address OK? Method Status Protocol
FastEthernet0/0 20.0.0.1 YES NVRAM up up
FastEthernet0/1 10.0.0.1 YES NVRAM up up
ATM0/1/0 unassigned YES NVRAM up up
SSLVPN-VIF0 unassigned NO unset up up
Virtual-Access1 unassigned YES unset up up
Virtual-Access2 unassigned YES unset up up
Dialer1 30.0.0.1 YES IPCP up up


I can print a single row like ( print $result[x]; )
However, How can i print just the row that has a certain IP in its row?

Ie:
How can i search the array for 20.0.0.1 and it will print:

FastEthernet0/0 20.0.0.1 YES NVRAM up up


Any ideas?
Thanks
 
Hi

With [tt]grep()[/tt], like this ?
Code:
[navy]@result[/navy][teal]=[/teal][green][i]<DATA>[/i][/green][teal];[/teal]

[navy]$ip[/navy][teal]=[/teal][green][i]'10.0.0.1'[/i][/green][teal];[/teal]

[b]print[/b] [b]grep[/b] [green][i]/\Q$ip\E/[/i][/green][teal],[/teal][navy]@result[/navy][teal];[/teal]

[b]__DATA__[/b]
Interface                  IP-Address      OK? Method Status                Protocol
FastEthernet0/0            20.0.0.1  YES NVRAM  up                    up
FastEthernet0/1            10.0.0.1   YES NVRAM  up                    up
ATM0/1/0                   unassigned      YES NVRAM  up                    up
SSLVPN-VIF0                unassigned      NO  unset  up                    up
Virtual-Access1            unassigned      YES unset  up                    up
Virtual-Access2            unassigned      YES unset  up                    up
Dialer1                    30.0.0.1   YES IPCP   up                    up

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top