Splunk Search

How to extract file name from the below raw data?

danroberts
Explorer

Hello, 

Can anyone help me to extract the below file name which is OU_..... from the below raw data. 

12:04:19.85 14/09/2023 directory="E:\data\Test" ECHO is off.

Volume in drive E is Data Volume Serial Number is 7808-CA1B

Directory of E:\data\Test 13/09/2023 13:22

<DIR> XXX\xxxx . 13/09/2023 13:22 <DIR> xxx\xxx .. 12/09/2023 09:31 95 xxx\xxx  dir_details.bat 13/09/2023 13:41 171 xxx\xxx  dir_details_copy.bat 07/09/2023 13:26 0 xxx\xxx  edsadsad.txt 07/09/2023 13:26 22 xxx\xxx  OU_kljdajdklsajkdl.zip 07/09/2023 13:26 22 xxx\xxx  OU_kljdajdklsajkewew.zip 07/09/2023 13:26 22 xxx\xxx  OU_kljdajdklsajkewewdsads.zip 6 File(s) 332 bytes 2 Dir(s) 20718067712 bytes free

 

splunk.PNG

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

ITWhisperer
SplunkTrust
SplunkTrust

Try something like this:

| rex max_match=0 "\s+\S+\s+\S+\s+\S+\s+\S+\s+(?<file>OU_\S+)"

In future, please paste the text of your event into a code block </> much like I have done with the SPL above. This prevents the text from being reformatted and losing spaces and new lines etc.

View solution in original post

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Try something like this:

| rex max_match=0 "\s+\S+\s+\S+\s+\S+\s+\S+\s+(?<file>OU_\S+)"

In future, please paste the text of your event into a code block </> much like I have done with the SPL above. This prevents the text from being reformatted and losing spaces and new lines etc.

0 Karma

danroberts
Explorer

Thanks for the rely, this has worked. 

Would this also work in a props.conf file ? 

I'm utilising a universal forwarder with a bat script to pull the data from the directory. 

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @danroberts ,

good for you, see next time!

Ciao and happy splunking

Giuseppe

P.S.: Karma Points are appreciated by all the contributors 😉

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @danroberts,

please try this:

| rex "(?<filename>OU_\w*\.\w*"

that you can test at https://regex101.com/r/UiiMSA/1

Ciao.

Giuseppe

0 Karma

danroberts
Explorer

Thanks for the reply, unfortunately this just pulls out one of the OU file names. 

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @danroberts,

please try this:

| rex max_match=0 "(?<filename>OU_\w*\.\w*"

Ciao.

Giuseppe

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

This is what you asked for

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

May 2026 Splunk Expert Sessions: Security & Observability

Level Up Your Operations: May 2026 Splunk Expert Sessions Whether you are refining your security posture or ...

Network to App: Observability Unlocked [May & June Series]

In today’s digital landscape, your environment is no longer confined to the data center. It spans complex ...

SPL2 Deep Dives, AppDynamics Integrations, SAML Made Simple and Much More on Splunk ...

Splunk Lantern is Splunk’s customer success center that provides practical guidance from Splunk experts on key ...