![Implementing Splunk 7(Third Edition)](https://wfqqreader-1252317822.image.myqcloud.com/cover/64/36700064/b_36700064.jpg)
上QQ阅读APP看书,第一时间看更新
rex
The rex command lets you use regular expressions to create fields. It can work against any existing field but, by default, will use the field _raw. Let's try one of the patterns that we wrote in our short regular expression primer:
sourcetype="impl_splunk_gen" | rex
"ip=(?P<subnet>\d+\.\d+\.\d+)\.\d+" | chart values(subnet) by
date_minute
This would create a table like this:
![](https://epubservercos.yuewen.com/DFC051/19470395608897106/epubprivate/OEBPS/Images/bd90c71e-8861-4662-b8a4-f9beae9a730c.png?sign=1739317995-f3CbQ3JxhSSZvBL3JDAr1vvbgHARMDVl-0-4dd8d893fbc60c47176ca16bb76fe980)
With the addition of the field argument, we can work against the ip field that is already being created automatically from the name=value pair in the event:
sourcetype="impl_splunk_gen" | rex field=ip "(?P<subnet>.*)\."|
chart values(subnet) by date_minute
This will create exactly the same result as the previous example.