我想从字符串中提取字符串并在字段下使用它

I want to extract the string from the string and use it under a field

我想从一个字符串中提取一个字符串...并在名为 source 的字段下使用它。

我试过这样写,但不行。

index = cba_nemis Status: J source = *AAP_ENC_UX_B.* |eval plan=upper
(substr(source,57,2)) |regex source = "AAP_ENC_UX_B.\w+\d+rp"|stats
count by  plan,source

例如..

来源=/p4products/nemis2/filehandlerU/encpr1/log/AAP_ENC_UX_B.az_in_aza_277U_ rp-20190722-054802.log 来源=/p4products/nemis2/filehandlerU/encpr2/log/AAP_ENC_UX_B.oh_in_ohf_ed_ph_ld-20190723-034121.log

我想提取字符串\ AAP_ENC_UX_B.az_in_aza_277U_ 从 1 日开始的 rp 和 AAP_ENC_UX_B.oh_in_ohf_ed_ph_ld 从 2 开始。

并将其与计数一起放在列源下..

我想要这样的结果...

           source                                   counts
AAP_ENC_UX_B.az_in_aza_277U_ rp                       1
AAP_ENC_UX_B.oh_in_ohf_ed_ph_ld                       1

您可以使用 [rex][1] 命令通过应用正则表达式从现有字段中提取新字段。

...search... 
| rex field=source ".+\/(?<source_v2>[\.\w\s]+)-.+"
| stats count by plan, source_v2

不过要小心:我将新字段命名为 source_v2,而你所要求的将 重写 现有的 source 字段,而无需你明确请求.只需在我的代码中将 source_v2 更改为 source,以防这是您想要的。

搜索会考虑这个新的 source_v2 字段。试试看这是否是您需要的。您可以轻松调整它以获得预期的结果。