0

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 data I want appended after each entry. I can of course fix it after I've collected the info but I'd like to avoid much data manipulation after parsing it the output.

Raw text: HE-EQM-01#show interfaces transceiver detail | begin Transmit Power Transmit Power Threshold Threshold Threshold Threshold Port (dBm) (dBm) (dBm) (dBm) (dBm) --------- ----------------- ---------- --------- --------- --------- Te1/2 -3.0 1.6 -1.3 -7.3 -11.3 Te1/3 -17.3 1.6 -1.3 -7.3 -11.3 Te1/4 -40.0 1.6 -1.3 -7.3 -11.3 Te2/2 -3.1 1.6 -1.3 -7.3 -11.3 Te2/3 -40.0 1.6 -1.3 -7.3 -11.3 Te2/4 -40.0 1.6 -1.3 -7.3 -11.3 Optical High Alarm High Warn Low Warn Low Alarm Receive Power Threshold Threshold Threshold Threshold Port (dBm) (dBm) (dBm) (dBm) (dBm) ------- ----------------- ---------- --------- --------- --------- Te1/2 -40.0 1.9 -1.0 -9.9 -13.9 Te1/3 -2.6 1.9 -1.0 -9.9 -13.9 Te1/4 -2.9 1.9 -1.0 -9.9 -13.9 Te2/2 -3.0 1.9 -1.0 -9.9 -13.9 Te2/3 -2.6 1.9 -1.0 -9.9 -13.9

Template:

Value interface (\w+\d\/\d+)
Value tx (-*\d+\.\d+)
Value rx (-*\d+\.\d+)

Start
  ^\s*Transmit\s*Power.+
  ^\s*${interface}\s+${tx} -> Record

Output:

[['Te1/2', '-3.0', ''],
['Te1/3', '-17.3', ''],
['Te1/4', '-40.0', ''],
['Te2/2', '-3.1', ''],
['Te2/3', '-40.0', ''],
['Te2/4', '-40.0', ''],
['Te1/2', '-40.0', ''],
['Te1/3', '-2.6', ''],
['Te1/4', '-2.9', ''],
['Te2/2', '-3.0', ''],
['Te2/3', '-2.6', ''],
['Te2/4', '-2.4', '']]

Preferably:

[['Te1/2', '-3.0', '-40.0'],
['Te1/3', '-17.3', '-2.6'],
['Te1/4', '-40.0', '-2.9'],
['Te2/2', '-3.1', '-3.0'],
['Te2/3', '-40.0', '-2.6'],
['Te2/4', '-40.0', '-2.4'],
nobody
  • 19,814
  • 17
  • 56
  • 77
Friday
  • 33
  • 5

1 Answers1

0

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.

PJProudhon
  • 835
  • 15
  • 17