I am trying to parse value from stackwise link output from Cisco router using textfsm but it seems like the textfsm config file is incorrect because it return the repetitive interface details. Below are sample of textfsm config.
Stackwise Virtual Link(SVL) Information:
----------------------------------------
Flags:
------
Link Status
-----------
U-Up D-Down
Protocol Status
---------------
S-Suspended P-Pending E-Error T-Timeout R-Ready
-----------------------------------------------
Switch SVL Ports Link-Status Protocol-Status
------ --- ----- ----------- ---------------
1 1 TwentyFiveGigE1/0/1 U R
TwentyFiveGigE1/0/2 U R
TwentyFiveGigE1/0/3 U R
2 1 TwentyFiveGigE2/0/4 U R
TwentyFiveGigE2/0/1 U R
TwentyFiveGigE2/0/2 U R
TwentyFiveGigE2/0/3 U R
Created template:
Value Required,Filldown SWITCH (\d)
Value Required,Filldown SVL (\d)
Value Required,Filldown PORTS (\S+)
Value Required,Filldown LINK_STATUS (\S+)
Value Required,Filldown PROTOCOL_STATUS (\S+)
Start
^Switch(\s+([A-Za-z]+\s+)+)[A-Za-z]+-([A-Za-z]+(\s+[A-Za-z]+)+)-[A-Za-z]+ -> Continue
^------ --- ----- ----------- ---------------
^${SWITCH}\s+${SVL}.* -> Continue
^(\d+)\s+(\d+)\s+${PORTS}\s+${LINK_STATUS}\s+${PROTOCOL_STATUS}\s+? -> Continue
^.* -> Record
EOF
but the output looks like :
[['1', '1', 'TwentyFiveGigE1/0/1', 'U', 'R'], ['1', '1', 'TwentyFiveGigE1/0/1', 'U', 'R'], ['1', '1', 'TwentyFiveGigE1/0/1', 'U', 'R'], ['2', '1', 'TwentyFiveGigE2/0/1', 'U', 'R'], ['2', '1', 'TwentyFiveGigE2/0/1', 'U', 'R'], ['2', '1', 'TwentyFiveGigE2/0/1', 'U', 'R']]
unable to fix any lead?
You were pretty close; you just need to match on (\d+ OR nothing) in your PORTS line:
(\d+|)
Output: