TextFSM Creating a Template

Took me a moment to understand 😉 but the Start is how you define where to start from the output fields and then you specified the possible value ( variable ) of each header to create the table to be filled in.

Start by creating a file.template

Value INTF (\S+)  <--- Non white space repeated more then one time.
Value IP (\S+)    <--- Non white space repeated more then one time.
Value STATUS (up|down|Admi\S)  
Value PROTOCOL (up|down)

Start
  ^Interface.*Protocol\s*$$ -> ShowIPIntBrief
# ^ = Begening with Interface
# . = one character
# * = any multiple character
# \s = any white space
# $$ = end of the line
# -> = record the data to "Variable"
ShowIPIntBrief
  ^${INTF}\s+${IP}.*${STATUS}\s+${PROTOCOL}\s*$$ -> Record

EOF

Interface                  IP-Address      OK? Method Status                Protocol
FastEthernet0              unassigned      YES unset  down                  down    
FastEthernet1              unassigned      YES unset  down                  down    
FastEthernet2              unassigned      YES unset  down                  down    
FastEthernet3              unassigned      YES unset  down                  down    
FastEthernet4              10.220.88.20    YES NVRAM  up                    up      
Vlan1                      unassigned      YES unset  down                  down

Leave a Comment