Splunk Search

How to match partial values of field a with partial values of field b ?

innoce
Path Finder

Hi, I want to match partial values of field a with partial values of field b.. I tried with match/like but no luck..

field a
AA\ABC$
BB\DCE$

field b
A=ABC,B=Domain,C=AB,D=XXX,E=NET
A=DCE,B=Domain,C=AB,D=XXX,E=NET

Now my results should return 

field a = field b
ABC    = ABC
DCE    = DCE

Could someone pls help me on this?

Labels (1)
0 Karma
1 Solution

gcusello
SplunkTrust
SplunkTrust

Hi @innoce ,

as @bowesmana said, you have to extract the second value from the second field.

Are you sure about the position of the second value in the second field?

if it's alway after "A=" and always in the beginning of the field, you could use the following regex:

<your_search>
| rex field=b "^A\=(?<A>[^,]*)"
| where a=A

that you can test at https://regex101.com/r/9hePOP/1 othrwise you have to modify the regex but using the same approach.

 Ciao.

Giuseppe

View solution in original post

0 Karma

bowesmana
SplunkTrust
SplunkTrust

Are you looking for any length partial match of field a with b?

i.e. if field a is AA\ABC$

and field B is 123456789A987654321

do you want a match because it contains A? which is a partial match?

0 Karma

innoce
Path Finder

@bowesmana , nope.. let me share the exact example values

field a = AAAAA\ABCDE-SS410009$

field b = A=AAAAA\ABCDE-SS410009,B=Domain,C=AB,D=XXX,E=NET

Now I want to match 
field a= AAAAA\ABCDE-SS410009
field b= AAAAA\ABCDE-SS410009
like this

0 Karma

bowesmana
SplunkTrust
SplunkTrust

Sorry, still not sure I get it, you say partial matches of both A and B, so for your second example what are the rules there?

field a = AAAAA\ABCDE-SS410009$

field b = A=AAAAA\ABCDE-SS410009,B=Domain,C=AB,D=XXX,E=NET

Now I want to match 
field a= AAAAA\ABCDE-SS410009
field b= AAAAA\ABCDE-SS410009
like this


In the above, you show that all characters up to and excluding the final $ sign are found in B, so you appear to be showing the longest match of A found in B.

So, if A had

AAAAA\ABCDE-PP921234$

would you expect to see AAAAA\ABCDE as a match result

and if A had

BBBBB\ABCDE-SS410009$

would you expect to see ABCDE-SS410009 as a match 

Also is the A= part in B related to field 'a'?

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @innoce ,

as @bowesmana said, you have to extract the second value from the second field.

Are you sure about the position of the second value in the second field?

if it's alway after "A=" and always in the beginning of the field, you could use the following regex:

<your_search>
| rex field=b "^A\=(?<A>[^,]*)"
| where a=A

that you can test at https://regex101.com/r/9hePOP/1 othrwise you have to modify the regex but using the same approach.

 Ciao.

Giuseppe

0 Karma

innoce
Path Finder

@gcusello , Thanks for the headsup.. as said, I modified the regex..

 

| rex "fieldb=(?P<fieldb>\w*[\-|\_]\w*)\,"
| rex "fielda\:\s+(?P<fielda_X>\w*\-\w*)\$"
and used the where condition to find matches
| where 'fielda_X'='fieldb'

 

 Its working now as expected..

0 Karma

gcusello
SplunkTrust
SplunkTrust

HI @innoce ,

good for you, see next time!

Ciao and happy splunking

Giuseppe

P.S.: Karma Points are appreciated by all the contributors 😉

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @innoce,

You don't need quotes id in the field names there isn't any space or special char.

Anyway, good for you, see next time!

let us know if we can help you more, or, please, accept one answer for the other people of Community.

Ciao and happy splunking

Giuseppe

P.S.: Karma Points are appreciated by all the contributors 😉

0 Karma

yuanliu
SplunkTrust
SplunkTrust

Looks like there is also a trailing "$" in field a.

<your_search>
| rex field=b "^A\=(?<A>[^,]*)"
| where a=A."$"

Something like that. 

0 Karma
Get Updates on the Splunk Community!

Introducing the Splunk Community Dashboard Challenge!

Welcome to Splunk Community Dashboard Challenge! This is your chance to showcase your skills in creating ...

Get the T-shirt to Prove You Survived Splunk University Bootcamp

As if Splunk University, in Las Vegas, in-person, with three days of bootcamps and labs weren’t enough, now ...

Wondering How to Build Resiliency in the Cloud?

IT leaders are choosing Splunk Cloud as an ideal cloud transformation platform to drive business resilience,  ...