Splunk Search

Get filename from path with rex

altink
Builder

Hello

I am trying to get filename (name.exe) from a full path (dir + filename) from windows folders, ex:

C:\dir1\dir2\filename.ext

using code as below:

 

index = os_sysmon NOT Image="*Sysmon*" EventCode=1
| rex field=Image "Executable=(?P<Executable>[^\\\]+)$"
| table Image Executable

 


Problem:
Executable always empty

Can you please advise?

best regards
Altin

Labels (1)
Tags (1)
0 Karma
1 Solution

richgalloway
SplunkTrust
SplunkTrust

Since the Image field does not contain the string "Executable=" the regular expression does not match and rex extracts nothing.  Try removing "Executable=" from the command.

---
If this reply helps you, Karma would be appreciated.

View solution in original post

0 Karma

richgalloway
SplunkTrust
SplunkTrust

The regular expression shown could be good, but we can't tell without seeing a sample event (not just a file path).

---
If this reply helps you, Karma would be appreciated.
0 Karma

altink
Builder

thank you @richgalloway  for the reply

attached is an example of my searchrex_issue_01.jpg

0 Karma

richgalloway
SplunkTrust
SplunkTrust

Since the Image field does not contain the string "Executable=" the regular expression does not match and rex extracts nothing.  Try removing "Executable=" from the command.

---
If this reply helps you, Karma would be appreciated.
0 Karma

altink
Builder

Thank You very much @richgalloway 

As You suggested, the following worked:

index = os_sysmon NOT Image="*Sysmon*" EventCode=1
| rex field=Image "(?P<Executable>[^\\\]+)$"
| table Image Executable
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Community Content Calendar, September edition

Welcome to another insightful post from our Community Content Calendar! We're thrilled to continue bringing ...

Splunkbase Unveils New App Listing Management Public Preview

Splunkbase Unveils New App Listing Management Public PreviewWe're thrilled to announce the public preview of ...

Leveraging Automated Threat Analysis Across the Splunk Ecosystem

Are you leveraging automation to its fullest potential in your threat detection strategy?Our upcoming Security ...