Hopefully this is more of a challenge than most of the find/replace perl scripts I've been searching through....
I want to parse data from cisco router and switch config files saved in a central folder, and place certain values in new files between meta-tags (xml specifically)
I want the script to detect if the file is a switch or router, based on the host name value, then use the appropriate "find" for that device.
My router config files have this line: "hostname uscalart0003" (no quotes in the file btw.) another router in NewYork is, "hostname usnynyrt0001" each host name will contain "rt" then 4 digits, mostly triple zero then 1-5 max.
My switches have this is the hostname value: "set system name uscalasw0002" or "set system name usnynysw0001" this time "sw000X" is how we can differentiate a router from a switch config, there are strings that overlap that make me think we need to add that step.
The values I wish to pull from the switch are in the lines:
#version 7.6(10) (echo this to a new file inbetween these meta-tags <version>7.6(10)</version>
set system name usnynysw0001 echo'd to <name>usnynysw0001</name>
set tacacs server 10.0.1.15
set tacacs server 10.1.1.15 (echo these to <tacacs>10.0.1.215, 10.1.1.215</tacacs> or <tacacs>10.0.1.15</tacacs> and <tacacs>10.1.1.15</tacacs>
Things like that, I can take the code an run with it, adding values to search for etc...
For the router files, let's start with this:
version 12.2 <version>12.2</version>
hostname uscalart0003 <name>uscalart0003</name>
boot system flash:c7200-p-mz.122-7b.bin <bootfile>c7200-p-mz.122-7b.bin</bootfile>
interface FastEthernet0/0 <interface>FastEthernet0/0</interface>
description trunk to uscalasw0002 3/21 <description>trunk to uscalasw0002 3/21</description>
duplex full <duplex>full</duplex>
let me know if you need more clarification, thanks for your time!