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
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.
Get Updates on the Splunk Community!

Tech Talk Recap | Mastering Threat Hunting

Mastering Threat HuntingDive into the world of threat hunting, exploring the key differences between ...

Observability for AI Applications: Troubleshooting Latency

If you’re working with proprietary company data, you’re probably going to have a locally hosted LLM or many ...

Splunk AI Assistant for SPL vs. ChatGPT: Which One is Better?

In the age of AI, every tool promises to make our lives easier. From summarizing content to writing code, ...