Hi all,
I'm quite new to TextFSM, and I'm trying to parse the output of the command "show interface counters errors". Here is a sample output of the command:
Port Align-Err FCS-Err Xmit-Err Rcv-Err UnderSize OutDiscards Gi0/1 1 2 3 4 5 6 Gi0/2 11 12 13 14 15 16 Port Single-Col Multi-Col Late-Col Excess-Col Carri-Sen Runts Giants Gi0/1 21 22 23 24 25 26 27 Gi0/2 211 222 233 244 255 266 277
What I would like, is this output when I parse the data:
['Gi0/1', '1', '2', '3', '4', '5', '6', '21', '22', '23', '24', '25', '26', '27'] ['Gi0/2', '11', '12', '13', '14', '15', '16', '211', '222', '233', '244', '255', '266', '277']
The first template I wrote is this one:
Value PORT (\S+(/\d+)+) Value ALIGNERR (\d+) Value FCSERR (\d+) Value XMITERR (\d+) Value RCVERR (\d+) Value UNDERSIZE (\d+) Value OUTDISCARDS (\d+) Value SINGLECOL (\d+) Value MULTICOL (\d+) Value LATECOL (\d+) Value EXCESSCOL (\d+) Value CARRISEN (\d+) Value RUNTS (\d+) Value GIANTS (\d+) Start ^Port\s+Align-Err.* ^${PORT}\s+${ALIGNERR}\s+${FCSERR}\s+${XMITERR}\s+${RCVERR}\s+${UNDERSIZE}\s+${OUTDISCARDS} -> Continue ^Port\s+Single-Col.* ^\S+\s+${SINGLECOL}\s+${MULTICOL}\s+${LATECOL}\s+${EXCESSCOL}\s+${CARRISEN}\s+${RUNTS}\s+${GIANTS} -> Record
However, the output is not right:
['Gi0/1', '21', '22', '23', '24', '25', '26', '21', '22', '23', '24', '25', '26', '27'] ['Gi0/2', '211', '222', '233', '244', '255', '266', '211', '222', '233', '244', '255', '266', '277']
I found a post on the forum giving a solution in pure Regex: TextFSM logic - Avoid capturing same data twice
When I adapt it to my needs, I have a match for what I need: https://regex101.com/r/DY0Meb/6
However, I'm unable to translate it in a TextFSM template, it fails. Here is my template:
Value PORT (\S+(/\d+)+) Value ALIGNERR (\d+) Value FCSERR (\d+) Value XMITERR (\d+) Value RCVERR (\d+) Value UNDERSIZE (\d+) Value OUTDISCARDS (\d+) Value SINGLECOL (\d+) Value MULTICOL (\d+) Value LATECOL (\d+) Value EXCESSCOL (\d+) Value CARRISEN (\d+) Value RUNTS (\d+) Value GIANTS (\d+) Start ^${PORT}\s+${ALIGNERR}\s+${FCSERR}\s+${XMITERR}\s+${RCVERR}\s+${UNDERSIZE}\s+${OUTDISCARDS}(?=.*\1\s+${SINGLECOL}\s+${MULTICOL}\s+${LATECOL}\s+${EXCESSCOL}\s+${CARRISEN}\s+${RUNTS}\s+${GIANTS}) -> Record
Any clues about how I can get the desired output ?
Any help would be very welcome :).
Thanks in advance !
No comments:
Post a Comment