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!

Splunk Observability Cloud's AI Assistant in Action Series: Auditing Compliance and ...

This is the third post in the Splunk Observability Cloud’s AI Assistant in Action series that digs into how to ...

Splunk Community Badges!

  Hey everyone! Ready to earn some serious bragging rights in the community? Along with our existing badges ...

What You Read The Most: Splunk Lantern’s Most Popular Articles!

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...