Splunk Search

How do I round only certain columns/fields ?

HattrickNZ
Motivator

How do I round only certain columns/fields ?
below this | foreach * [eval <<FIELD>>=round('<<FIELD>>',2)] will round all the fields to 2 decimal places.
How do I do it for just fields that start with kpi

I was thinking something like this,
| foreach * [eval <<kpi*>>=round('<<kpi*>>',2)]
but I think there might be more to it. Can you advise?

sample data search:

| makeresults 
 | eval data = "
  1-Sep    0 55.5555 57.7777;
  2-Sep    0 56.6666 58.8888; 
  " 
 | makemv delim=";" data 
 | mvexpand data 
 | rex field=data "(?<Date>\d+-\w+)\s+(?<Other1>\d+)\s+(?<kpi2>\d+(\.\d+)?)\s+(?<kpi3>\d+(\.\d+)?)" 
 | fields + Date Other1 kpi2 kpi3
 | search Other1=*
 | foreach * [eval <<FIELD>>=round('<<FIELD>>',2)]
Tags (2)
0 Karma
1 Solution

HattrickNZ
Motivator

shoot, think I worked that out as I asked the question.

| foreach kpi* [eval <<FIELD>>=round('<<FIELD>>',2)]

View solution in original post

0 Karma

HattrickNZ
Motivator

shoot, think I worked that out as I asked the question.

| foreach kpi* [eval <<FIELD>>=round('<<FIELD>>',2)]

0 Karma
Get Updates on the Splunk Community!

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...