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!

Registration for Splunk University is Now Open!

Are you ready for an adventure in learning?   Brace yourselves because Splunk University is back, and it's ...

Splunkbase | Splunk Dashboard Examples App for SimpleXML End of Life

The Splunk Dashboard Examples App for SimpleXML will reach end of support on Dec 19, 2024, after which no new ...

Understanding Generative AI Techniques and Their Application in Cybersecurity

Watch On-Demand Artificial intelligence is the talk of the town nowadays, with industries of all kinds ...