Computing.Net > Forums > Unix > Shell script help

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Shell script help

Reply to Message Icon

Name: Hugo
Date: December 12, 2007 at 07:47:15 Pacific
OS: Sol 9
CPU/Ram: 4GB
Product: SunFire v240
Comment:

Hi.

Any one know how to extract Interface name and ip address for each working (UP) interface on Cisco device configuration? Configuration is already on flat files. Config file has many entries like one below:

interface GigabitEthernet0/0
description To site LAN
ip address 10.2.122.241 255.255.255.252
ip access-group virus-security in
duplex auto
speed auto
media-type rj45

Need to grep for each device config only interface info and ip address, as long as interface is not shutdown.

Thank you very much.



Sponsored Link
Ads by Google

Response Number 1
Name: Ankit Jain
Date: December 16, 2007 at 20:21:04 Pacific
Reply:

Try with this code

SEARCH1="interface"
SEARCH2="ip address"
FILE="path of file"

cat $FILE | \
while read line
do
INDEX1="`awk -v a="$line" -v b="$SEARCH1" 'BEGIN{print index(a,b)}'` "
INDEX2="`awk -v a="$line" -v b="$SEARCH2" 'BEGIN{print index(a,b)}'` "
if [ INDEX1 -ne 0 ] ;
then
EXTRACT1="`awk -v a="$line" 'BEGIN{print substr(a,11)}'`" #extract from line startting from 11th char(leaving interface) upto end
EXTRACT2="`awk -v a="$var" 'BEGIN{print substr(a,11)}'`"

Jain Sahab


0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Shell script help

Shell Scripting Help www.computing.net/answers/unix/shell-scripting-help/5020.html

C Shell script help! www.computing.net/answers/unix/c-shell-script-help/3108.html

c shell script help PLEASE www.computing.net/answers/unix/c-shell-script-help-please/4355.html