Splunk Search

How to replace all values for a field with "Other" that do not equal values A, B, or C?

ttoine
Explorer

I am working on a pie chart to identify the main categories of some data. Below are some possible values:
Apple
Peach
Perry
Strawberry
Blueberry
Cranberry

I would like to replace the value by "Other" when this is not Apple, Peach or Perry. How could I do that? using replace? using if?

Tags (2)
0 Karma

sundareshr
Legend

Try this

.... | eval category=if(category="Apple" OR category="Peach" OR category="Perry", category, "Other")
0 Karma

ttoine
Explorer

thanks. do you think it would be possible to do this in an other way that would use less resources?

0 Karma

somesoni2
SplunkTrust
SplunkTrust

Do this after your aggregation (stats etc).

0 Karma

ttoine
Explorer

after timechart, this is not working.

0 Karma

sundareshr
Legend

The other option is using rex mode=sed or replace() but not sure how much more efficient that will be. Maybe I am not understanding your concern?

0 Karma

ttoine
Explorer

if I want to use rex mode=sed, or replace, how can I set the condition?

0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...