Splunk Search

Eval and If else value return or else null

Splunk_rocks
Path Finder

Hello Splunkers,

Im constructing Eval field " user1" actually user field contain 5 digit number so i have to construct a EVAL field like

index= XXX| "xxxxx" |eval user1 = if((user_pin > 0), "user_pin", "Unknown") | table user1 user_pin

If "user1" field is 7 digit then in just return actual 7 digit number or else if it is string just say "null value"

EVAL-user = if((user1== 5 digit number ) "reportactull number ", "report null value ")

Please let me know

Tags (2)
0 Karma
1 Solution

woodcock
Esteemed Legend

You say both 7-digit and 5-digit but I am assuming that you mean the latter, so like this:

EVAL-user=if(match(user1, "^\d{5}$"), user1, "null value")

View solution in original post

0 Karma

woodcock
Esteemed Legend

You say both 7-digit and 5-digit but I am assuming that you mean the latter, so like this:

EVAL-user=if(match(user1, "^\d{5}$"), user1, "null value")
0 Karma

Splunk_rocks
Path Finder

Thanks that worked ..if i want to capture word or digit In case 5 -7 digit number or 5-8 word id.

0 Karma

Splunk_rocks
Path Finder

I need to match below to construct eval field.

user
X234578
wertyui
kxtur
lytue23

0 Karma

woodcock
Esteemed Legend

Change d{5} to d{5-8} or similar.

0 Karma
Get Updates on the Splunk Community!

Built-in Service Level Objectives Management to Bridge the Gap Between Service & ...

Wednesday, May 29, 2024  |  11AM PST / 2PM ESTRegister now and join us to learn more about how you can ...

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer at Splunk .conf24 ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...

Share Your Ideas & Meet the Lantern team at .Conf! Plus All of This Month’s New ...

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