Splunk Search

Could you please help me with using REX/REGEX inside eval?

usscommunity
Loves-to-Learn Lots

Hi

Could you please help me with using REX/REGEX inside eval? Here is what I'm trying to do 

| makeresults
| eval User="user1=test@domain.com | use1=test1"
| makemv delim="|" User | mvexpand User
| fields - _time
| eval signature="87347,123,1,0,84"
| makemv signature delim=","
| mvexpand signature
| eval account=if(like(signature,"87347") AND like(User,"%@%" )," REGEX USER TO KEEP EVERYTHING BEFORE @ "," DONT MAKE ANY CHANGES , KEEP THE USER WITH @")

Thanks 

 

 

Labels (4)
0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Given that the only time you change user is if signature is 87347 and in that instance you want everything before the @, just use split

| eval account=if(like(signature,"87347"),mvindex(split(user,"@"),0),user)
0 Karma

yuanliu
SplunkTrust
SplunkTrust

An alternative is to use replace

| eval account=if(like(signature,"87347"),replace(user,"@.*",""),user)

Like ITWhisperer said, you do not need to test for %@%  if your final operation is to get rid of @%.  In the code you illustrated, the test for signature also do not include wildcard.  Therefore, like(signature, "87347") is semantically identical to signature=="87347", but slightly more expensive.  Thanks for bring my attention to function "like()", BTW.  I only used match() before.

0 Karma
Get Updates on the Splunk Community!

Welcome to the Splunk Community!

(view in My Videos) We're so glad you're here! The Splunk Community is place to connect, learn, give back, and ...

Tech Talk | Elevating Digital Service Excellence: The Synergy of Splunk RUM & APM

Elevating Digital Service Excellence: The Synergy of Real User Monitoring and Application Performance ...

Adoption of RUM and APM at Splunk

    Unleash the power of Splunk Observability   Watch Now In this can't miss Tech Talk! The Splunk Growth ...