Skip to content Skip to sidebar Skip to footer

TextFSM Logic - Avoid Capturing Same Data Twice

I'm trying to record optics light readings off a cisco RFGW. The issue I'm facing is that because of the way the data is displayed I capture the Physical interface twice and the d

Solution 1:

I decomposed a bit. What you want is:

  1. Match the interface: (\w+\d\/\d+)
  2. After a few spaces, match the transmit power: (-?\d\.\d+) (use of ? is preferable here as you don't want multiple following -)
  3. Find in the following text the same interface again: (?=.*\1)
  4. That one followed by the received power (same as 2.)

If you assemble it all, you get:

(\w+\d+\/\d+)\s+(-?\d+\.\d+)(?=.+\1\s+(-?\d+\.\d+))
                                      ^
Capturing in the lookahead, that way relevant data is captured, but not eaten by the engine, which would prevent following matches.

See the demo.


Post a Comment for "TextFSM Logic - Avoid Capturing Same Data Twice"