Splunk Search

How to Build an If Statement based on if a field contains a string

katzr
Path Finder

For every record where the field Test contains the word "Please" - I want to replace the string with "This is a test", below is the logic I am applying and it is not working- I tried using case, like, and a changed from " to ' and = to == but I cannot get anything to work.

| eval Test=if(Test=="Please", "This is a test", Test)

0 Karma
1 Solution

somesoni2
SplunkTrust
SplunkTrust

Try like this

...| eval Test=if(match(Test,"Please"),"This is a test", Test)

The equal sign does the exact comparison (value should match exactly). Since you want to check for "contains", you can use match(Test,"Please") or like(Test,"%Please%").

View solution in original post

somesoni2
SplunkTrust
SplunkTrust

Try like this

...| eval Test=if(match(Test,"Please"),"This is a test", Test)

The equal sign does the exact comparison (value should match exactly). Since you want to check for "contains", you can use match(Test,"Please") or like(Test,"%Please%").

katzr
Path Finder

thank you this works!

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 ...