Splunk Search

How to edit the syntax for my rex search to extract the folder name from a source path?

Federica_92
Communicator

Hi everyone,

I'm struggling with this rex expression:

 query | rex field=source  "/var/syslog*(?<remote_source>\w+)/*.log"

  /var/syslog/name_folder/2015-08-11.log

I need to get the folder name. Could someone please help me to correct this regex?

Thank you a lot! : )

0 Karma
1 Solution

woodcock
Esteemed Legend

Like this:

query | rex field=source  "^\/(?:[^\/]+\/){2}(?<remote_source>[^\/]+)\/"

View solution in original post

woodcock
Esteemed Legend

Like this:

query | rex field=source  "^\/(?:[^\/]+\/){2}(?<remote_source>[^\/]+)\/"

richgalloway
SplunkTrust
SplunkTrust

Don't forget the escape characters.

^\/(?:[^\/]+\/){2}([^\/]+)\/
---
If this reply helps you, Karma would be appreciated.

woodcock
Esteemed Legend

quite correct; Fixed another markdown mistake, too (answer updated and tested).

0 Karma

Federica_92
Communicator

Thank you : )

0 Karma
Get Updates on the Splunk Community!

New in Observability Cloud - Explicit Bucket Histograms

Splunk introduces native support for histograms as a metric data type within Observability Cloud with Explicit ...

Updated Team Landing Page in Splunk Observability

We’re making some changes to the team landing page in Splunk Observability, based on your feedback. The ...

New! Splunk Observability Search Enhancements for Splunk APM Services/Traces and ...

Regardless of where you are in Splunk Observability, you can search for relevant APM targets including service ...