我试图从cisco RFGW上记录光学读数。我面临的问题是,由于数据的显示方式,我捕获物理接口两次,并在每次输入后追加我想要的数据。在我收集了信息之后,我当然可以修复它,但是我想在解析输出后避免大量数据操作。
原始文字:
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
模板:
Value interface (\w+\d\/\d+)
Value tx (-*\d+\.\d+)
Value rx (-*\d+\.\d+)
Start
^\s*Transmit\s*Power.+
^\s*${interface}\s+${tx} -> Record
输出:
[['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', '']]
最好:
[['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'],
答案 0 :(得分:0)
我分解了一下。你想要的是:
(\w+\d\/\d+)
(-?\d\.\d+)
(此处最好使用?
,因为您不希望多次跟踪-
)(?=.*\1)
如果你全部组装,你会得到:
(\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.
请参阅demo。