Splunk Search

Help with regex to remove first part of string?

tomapatan
Communicator

I have 2 fields: the values of fieldA are present in fieldB and I need to remove the first part of fieldB up to the values present in fieldA.

For example:

fieldA = BP498

fieldB = "A1John/Doe SmithBP498 XX XX XX"

Desired:

fieldB="BP498 XX XX XX"

Thanks in advance.

Labels (2)
0 Karma
1 Solution

kamlesh_vaghela
SplunkTrust
SplunkTrust

@tomapatan 

Can you please try this?

YOUR_SEARCH
| eval fieldB=fieldA+mvindex(split(fieldB,fieldA),1)

 

My Sample Search :

| makeresults 
| eval fieldA = "BP498",fieldB = "A1John/Doe SmithBP498 XX XX XX"
| rename comment as "upto this is sample data" 
| eval fieldB=fieldA+mvindex(split(fieldB,fieldA),1)

 

Screenshot 2022-09-27 at 3.37.44 PM.png

I hope this will help you. 

Thanks
KV
If any of my replies help you to solve the problem Or gain knowledge, an upvote would be appreciated.

 

 

View solution in original post

tomapatan
Communicator

worked for me, much appreciated.

0 Karma

kamlesh_vaghela
SplunkTrust
SplunkTrust

@tomapatan 

Can you please try this?

YOUR_SEARCH
| eval fieldB=fieldA+mvindex(split(fieldB,fieldA),1)

 

My Sample Search :

| makeresults 
| eval fieldA = "BP498",fieldB = "A1John/Doe SmithBP498 XX XX XX"
| rename comment as "upto this is sample data" 
| eval fieldB=fieldA+mvindex(split(fieldB,fieldA),1)

 

Screenshot 2022-09-27 at 3.37.44 PM.png

I hope this will help you. 

Thanks
KV
If any of my replies help you to solve the problem Or gain knowledge, an upvote would be appreciated.

 

 

FelixLeh
Contributor

That's a cool way to remove something from a string! I'll add that to my repertoire, thanks!

0 Karma
Get Updates on the Splunk Community!

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...