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!

Introducing Splunk Enterprise 9.2

WATCH HERE! Watch this Tech Talk to learn about the latest features and enhancements shipped in the new Splunk ...

Adoption of RUM and APM at Splunk

    Unleash the power of Splunk Observability   Watch Now In this can't miss Tech Talk! The Splunk Growth ...

Routing logs with Splunk OTel Collector for Kubernetes

The Splunk Distribution of the OpenTelemetry (OTel) Collector is a product that provides a way to ingest ...