TextFSM with repeating regex values?

65 views Asked by At

I am having a difficult time understanding what I thought would be an easy concept. When the output of textFSM has repeating regex values, I am not able to extract the data properly.

Simple example: Input:

1 2 
3 4

TextFSM template:

Value FIRST (\d+)
Value SECOND (\d+)
Value THIRD (\d+)
Value FORTH (\d+)

Start
  ^${FIRST} ${SECOND}
  ^${THIRD} ${FORTH} -> Record

Output:

[
    {
        "FIRST": "3",
        "FORTH": "",
        "SECOND": "4",
        "THIRD": ""
    }
]

The real life example of this is trying to parse "ip -s -s link show" and the current version of ip doesn't support the -j flag. I'll be experimenting with using the -o flag, but I am totally confused why the above doesn't work.

Actual example of where this is a problem -- seems impossible to extract TX/RX values:

2: eth0@if15: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default qlen 1000
    link/ether 10:5d:b2:02:0e:fd brd ff:ff:ff:ff:ff:ff link-netnsid 0
    RX: bytes  packets  errors  dropped overrun mcast   
    567635797  6154603  0       18089   0       0       
    RX errors: length   crc     frame   fifo    missed
               0        0       0       0       0       
    TX: bytes  packets  errors  dropped carrier collsns 
    41624009   340091   0       0       0       0       
    TX errors: aborted  fifo   window heartbeat transns
               0        0       0       0       6     
1

There are 1 answers

0
netnem On

Update:

I finally figured this out.

Value FIRST (\d+)
Value SECOND (\d+)
Value THIRD (\d+)
Value FORTH (\d+)

Start
  ^${FIRST} ${SECOND} -> SecondLine

SecondLine
  ^${THIRD} ${FORTH} -> Record