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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Better way to do this rather then sed ?

Status
Not open for further replies.

sumncguy

IS-IT--Management
May 22, 2006
118
US
results

2520 chassis, Hw Serial#: 89678884, Hw Revision: M"
2500 chassis, Hw Serial#: 86192210, Hw Revision: F"
WS-C3548-XL chassis"
WS-C2924C-XL chassis"
cisco WS-C3548-XL"
Cisco Catalyst 3550 48 10/100 baseT ports + 2 Gig uplinks fixed configuration Layer 2/3 Ethernet Switch"
Cisco Systems Catalyst 6500 6-slot Chassis System"
Cisco Systems Catalyst 6500 6-slot Chassis System"
Cisco Systems Catalyst 6500 6-slot Chassis System"
Cisco Catalyst 3550 48 10/100 baseT ports + 2 Gig uplinks fixed configuration Layer 2/3 Ethernet Switch"
Cisco Catalyst 3550 48 10/100 baseT ports + 2 Gig uplinks fixed configuration Layer 2/3 Ethernet Switch"
Cisco Catalyst 3550 48 10/100 baseT ports + 2 Gig uplinks fixed configuration Layer 2/3 Ethernet Switch"
Cisco Catalyst 3550 48 10/100 baseT ports + 2 Gig uplinks fixed configuration Layer 2/3 Ethernet Switch"
Cisco Catalyst 3550 48 10/100 baseT ports + 2 Gig uplinks fixed configuration Layer 2/3 Ethernet Switch"
Cisco Catalyst 3550 48 10/100 baseT ports + 2 Gig uplinks fixed configuration Layer 2/3 Ethernet Switch"
Cisco Catalyst 3550 48 10/100 baseT ports + 2 Gig uplinks fixed configuration Layer 2/3 Ethernet Switch"
Cisco Catalyst 3550 24 10/100 baseT ports + 2 Gig uplinks fixed configuration Layer 2/3 Ethernet Switch"
Cisco Catalyst 3550 48 10/100 baseT ports + 2 Gig uplinks fixed configuration Layer 2/3 Ethernet Switch"
Cisco Systems Catalyst 6500 3-slot Chassis System"
Cisco Systems Catalyst 6500 3-slot Chassis System"
Cisco Systems Catalyst 6500 6-slot Chassis System"
Cisco Systems Catalyst 6500 3-slot Chassis System"
3620 chassis, Hw Serial#: 646463785, Hw Revision: 0x81"
7206VXR chassis, Hw Serial#: 29810554, Hw Revision: A"

All I want is the following :

2520
2500
WS-C3548-XL
WS-C2924C-XL
cisco WS-C3548-XL
3550 48 10/100 + 2 Gig
6500 6-slot
6500 6-slot
6500 6-slot
3550 48 10/100 + 2 Gig
3550 48 10/100 + 2 Gig
3550 48 10/100 + 2 Gig
3550 48 10/100 + 2 Gig
3550 48 10/100 + 2 Gig
3550 48 10/100 + 2 Gig
3550 48 10/100 + 2 Gig
3550 24 10/100 + 2 Gig
3550 48 10/100 + 2 Gig
6500 3-slot
6500 3-slot
6500 6-slot
6500 3-slot
3620
7206VXR
7206VXR
7206VXR
2621XM
7206VXR
7206VXR
7206VXR


But I just dont like how Im getting there ... if this aint spaghetti code, I dont know what is ..




#! /bin/ksh
cat seedfile | awk '{print $4}' | while read x
do

snmpwalk -c xxxxxxx $x .1.3.6.1.2.1.47.1.1.1.1.2.1 | sed 's/.*STRING: "//' |
sed -e 's/Cisco Systems Catalyst"//' -e 's/Cisco Catalyst //' |
sed -e 's/Cisco Systems Catalyst //' -e 's/Chassis//' -e 's/System//' |
sed -e 's/ uplinks fixed config.*//' -e 's/, Hw Serial.*//' -e 's/\"//g' -e 's/c
hassis//' -e 's/baseT ports//'
done

Thanks again ...
 
This really looks like a case for a perl script. perl has a bit of a steep learnign curve but once you've got the basics it dows bits and pieces like this easy-peasy.

Ceci n'est pas une signature
Columb Healy
 
I think sed is appropriate for this, although there is no reason to break it into multiple scripts like that. I also removed the "useless use of cat":

[tt]#! /bin/ksh
awk '{print $4} seedfile ' | while read x
do

snmpwalk -c xxxxxxx $x .1.3.6.1.2.1.47.1.1.1.1.2.1 | sed 's/.*STRING: "//
s/Cisco .*Catalyst //
s/ Chassis.*//i
s/ uplinks fixed config.*//
s/, Hw Serial.*//
s/\"//g
s/ baseT ports//'

done[/tt]

I have also removed some redundant searches by using .* in the regex and the /i option at the end of the search to ignore case.

Annihilannic.
 


Thanks Annie ... that works great and its faster too.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top