Splunk Search

extract part of path that may or may not contain space

sarit_s
Communicator

Hello

i have source path that looks like :

s3://splunk/OTHER/1/OTHER/Star J750/pjserialnumber/2019-05-06T13:40:37.490Z_1.91.0.192_1.88.0.0_31.29.60.11592/metadata.json

i want to extract "pjserialnumber"
but since i have space in "Star j750"
my regex is not working

rex field=source \/splunk\/\w+\/\w+\/\w+\/(?<SerialNumber>\w+)

my problem is that i want to create a macro from this regex but not all the path's contain space

how can i fix both of the problems ?

thanks

Tags (2)
0 Karma
1 Solution

vnravikumar
Champion

Hi

Give a try

| makeresults 
| eval msg="s3://splunk/OTHER/1/OTHER/Star J750/pjserialnumber/2019-05-06T13:40:37.490Z_1.91.0.192_1.88.0.0_31.29.60.11592/metadata.json" 
| eval SerialNumber = mvindex(split(msg,"/") ,7)

View solution in original post

0 Karma

gouravdashtcs
Loves-to-Learn

Hello Sarit,

Kindly find the modified rex query for your reference.

rex field = source \/splunk\/\w+\/\w+\/\w+\/\w+\s+\w+\/(?\w+)

0 Karma

lakshman239
Influencer

You can change it to something like \/splunk\/\w+\/\w+\/\w+\/(?<SerialNumber>[^\/]*)\/

https://regex101.com/r/lcAZF0/3

0 Karma

sarit_s
Communicator

this is taking the wrong part of the path

0 Karma

vnravikumar
Champion

Hi

Give a try

| makeresults 
| eval msg="s3://splunk/OTHER/1/OTHER/Star J750/pjserialnumber/2019-05-06T13:40:37.490Z_1.91.0.192_1.88.0.0_31.29.60.11592/metadata.json" 
| eval SerialNumber = mvindex(split(msg,"/") ,7)
0 Karma

sarit_s
Communicator

work perfect !

0 Karma
Get Updates on the Splunk Community!

Announcing Scheduled Export GA for Dashboard Studio

We're excited to announce the general availability of Scheduled Export for Dashboard Studio. Starting in ...

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics GA in US-AWS!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...