简体   繁体   English

SPLUNK 查询:需要使用定界符拆分列表中的字符串

[英]SPLUNK Query : need to split a string in a list using delimiter

eg: list = { abc::12345, xyz::345}.例如:list = {abc::12345, xyz::345}。 requirement is I have to get {abc, xyz} as query result.要求是我必须得到 {abc, xyz} 作为查询结果。

needs stats count of the values in the list after removing the part after delimiter::删除定界符后的部分后需要列表中值的统计计数::

There's probably more than one way to do it (as is common with Splunk), but I like rex .可能有不止一种方法可以做到这一点(这在 Splunk 中很常见),但我喜欢rex Here's a run-anywhere example query that shows how.这是一个显示如何运行的随处运行示例查询。

| makeresults 
| eval list = "{ abc::12345, xyz::345}" 
``` The above creates demo data.  Remove IRL ```
``` Use a regular expression to extract keywords from before "::" into field 'f' ```
| rex field=list max_match=0 "[\s\{,](?<f>[^:]+)" 
``` Count the number of (non-unique) values in f ```
| eval count=mvcount(f)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM