Getting Data In

How do I modify my rex command to remove directory location from path?

jeradb
Explorer

Here is my current rex command - 

 

 

EventCode=1004
| rex field=_raw "Files: (?<Media_Source>.+?\.txt)" 
| table Media_Source

 

 

 

My source data looks like this -

 

 

Files: C:\ProgramData\Roxio Log Files\Test.test_user_20240305122549.txt SHA1: 73b710056457bd9bda5fee22bb2a2ada8aa9f3e0

 

 

 

My current rex result is -  C:\ProgramData\Roxio Log Files\Test.test_user_20240305122549.txt

How do I make it - Test.test_user_20240305122549.txt

Im trying to drop - C:\ProgramData\Roxio Log Files\

Labels (2)
0 Karma
1 Solution

yuanliu
SplunkTrust
SplunkTrust

This question better belongs to Splunk Search.  Anyway, let me generalize your ask: You want the last part of the file path (which is usually file name).  You can use regex.  But a more semantic and potentially cheaper solution is to use split and mvindex.

EventCode=1004
| rex field=_raw "Files: (?<Media_Source>.+?\.txt)"
| table Media_Source
| eval Filename = mvindex(split(Media_Source, "\"), -1)

If you really want to use regex, you can do

EventCode=1004
| rex field=_raw "Files: .+?\\(?<Media_Source>[^\\]+\.txt)" 
| table Media_Source

Hope this helps.

View solution in original post

Tags (2)
0 Karma

yuanliu
SplunkTrust
SplunkTrust

This question better belongs to Splunk Search.  Anyway, let me generalize your ask: You want the last part of the file path (which is usually file name).  You can use regex.  But a more semantic and potentially cheaper solution is to use split and mvindex.

EventCode=1004
| rex field=_raw "Files: (?<Media_Source>.+?\.txt)"
| table Media_Source
| eval Filename = mvindex(split(Media_Source, "\"), -1)

If you really want to use regex, you can do

EventCode=1004
| rex field=_raw "Files: .+?\\(?<Media_Source>[^\\]+\.txt)" 
| table Media_Source

Hope this helps.

Tags (2)
0 Karma
Get Updates on the Splunk Community!

Optimize Cloud Monitoring

  TECH TALKS Optimize Cloud Monitoring Tuesday, August 13, 2024  |  11:00AM–12:00PM PST   Register to ...

What's New in Splunk Cloud Platform 9.2.2403?

Hi Splunky people! We are excited to share the newest updates in Splunk Cloud Platform 9.2.2403! Analysts can ...

Stay Connected: Your Guide to July and August Tech Talks, Office Hours, and Webinars!

Dive into our sizzling summer lineup for July and August Community Office Hours and Tech Talks. Scroll down to ...