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
Get Updates on the Splunk Community!

Your Guide to SPL2 at .conf24!

So, you’re headed to .conf24? You’re in for a good time. Las Vegas weather is just *chef’s kiss* beautiful in ...

Get ready to show some Splunk Certification swagger at .conf24!

Dive into the deep end of data by earning a Splunk Certification at .conf24. We're enticing you again this ...

Built-in Service Level Objectives Management to Bridge the Gap Between Service & ...

Now On-Demand Join us to learn more about how you can leverage Service Level Objectives (SLOs) and the new ...