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!

[Puzzles] Solve, Learn, Repeat: Dynamic formatting from XML events

This challenge was first posted on Slack #puzzles channelFor a previous puzzle, I needed a set of fixed-length ...

Enter the Agentic Era with Splunk AI Assistant for SPL 1.4

  &#x1f680; Your data just got a serious AI upgrade — are you ready? Say hello to the Agentic Era with the ...

Stronger Security with Federated Search for S3, GCP SQL & Australian Threat ...

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...