Splunk Search

Setting field value based on another field

tsheets13
Communicator

I have a value in my events called type, which is a single digit integer (1, 2, 3, etc.)

I would like to create a new string field in my search based on that value.

So, something like this pseudocode...

if type = 1 then desc = "pre"
if type = 2 then desc = "current"
if type = 3 then desc = "post"

I realize the splunk doesn't do if/then statements but I thought that was the easiest way to explain.

Thanks

Labels (1)
0 Karma
1 Solution

gcusello
SplunkTrust
SplunkTrust

Hi @tsheets13,
you have to use eval command with case option:

| eval desc=case(type="1","pre",type="2","current",type="3","post")

for more infos see at https://docs.splunk.com/Documentation/Splunk/8.0.2/SearchReference/ConditionalFunctions

Ciao.
Giuseppe

View solution in original post

gcusello
SplunkTrust
SplunkTrust

Hi @tsheets13,
you have to use eval command with case option:

| eval desc=case(type="1","pre",type="2","current",type="3","post")

for more infos see at https://docs.splunk.com/Documentation/Splunk/8.0.2/SearchReference/ConditionalFunctions

Ciao.
Giuseppe

tsheets13
Communicator

Perfect! Thank you

0 Karma
Get Updates on the Splunk Community!

Detecting Remote Code Executions With the Splunk Threat Research Team

REGISTER NOWRemote code execution (RCE) vulnerabilities pose a significant risk to organizations. If ...

Observability | Use Synthetic Monitoring for Website Metadata Verification

If you are on Splunk Observability Cloud, you may already have Synthetic Monitoringin your observability ...

More Ways To Control Your Costs With Archived Metrics | Register for Tech Talk

Tuesday, May 14, 2024  |  11AM PT / 2PM ET Register to Attend Join us for this Tech Talk and learn how to ...