Splunk Search

How do I edit my if else search for comparing two values?

sushmitha_mj
Communicator

I have a field Name and a field ID. So a person named Adam has an ID 1. The next time Adam is renamed Rob, but ID remains 1, and next time, he could become Sam.
I want to write a search that would return the original name Adam in all three cases where ID is 1.

Table structure :
Name ------ ID
Adam ------ 1
Rob -------- 1
Sam -------- 1
So to know which value is the original, I have a theory. There is a pattern to all names: the 2nd and 3rd letters are always "da" . How can I retrieve this value?
My search :

| stats values(Name)  by ID | eval original_name=if (substr(Name,2,2)="da",names)     

Is this the right way or should I use a regex to do this?

0 Karma
1 Solution

aljohnson_splun
Splunk Employee
Splunk Employee

I think you could use stats earliest to do this.

... | stats earliest(Name) by ID

as long as you look far back enough in time to make sure you're including the earliest time.

View solution in original post

woodcock
Esteemed Legend

Try this:

...| stats values(Name) AS names BY ID | eval original_name=coalesce(
(substr(mvindex(names,0),2,2)="da"),mvindex(names,0),
(substr(mvindex(names,1),2,2)="da"),mvindex(names,1),
(substr(mvindex(names,2),2,2)="da"),mvindex(names,2),
(substr(mvindex(names,3),2,2)="da"),mvindex(names,3),
(substr(mvindex(names,4),2,2)="da"),mvindex(names,4),
(substr(mvindex(names,5),2,2)="da"),mvindex(names,5))

aljohnson_splun
Splunk Employee
Splunk Employee

I think you could use stats earliest to do this.

... | stats earliest(Name) by ID

as long as you look far back enough in time to make sure you're including the earliest time.

sushmitha_mj
Communicator

Thank you... It worked...

0 Karma

fdi01
Motivator

see what Mr aljohnson_splunk do, just renam like:

... | stats earliest(Name) as original_name by ID

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Community Content Calendar, September edition

Welcome to another insightful post from our Community Content Calendar! We're thrilled to continue bringing ...

Splunkbase Unveils New App Listing Management Public Preview

Splunkbase Unveils New App Listing Management Public PreviewWe're thrilled to announce the public preview of ...

Leveraging Automated Threat Analysis Across the Splunk Ecosystem

Are you leveraging automation to its fullest potential in your threat detection strategy?Our upcoming Security ...