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!

Dashboards: Hiding charts while search is being executed and other uses for tokens

There are a couple of features of SimpleXML / Classic dashboards that can be used to enhance the user ...

Splunk Observability Cloud's AI Assistant in Action Series: Explaining Metrics and ...

This is the fourth post in the Splunk Observability Cloud’s AI Assistant in Action series that digs into how ...

Brains, Bytes, and Boston: Learn from the Best at .conf25

When you think of Boston, you might picture colonial charm, world-class universities, or even the crack of a ...