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

Introducing the Splunk Community Dashboard Challenge!

Welcome to Splunk Community Dashboard Challenge! This is your chance to showcase your skills in creating ...

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

Wednesday, May 29, 2024  |  11AM PST / 2PM ESTRegister now and join us to learn more about how you can ...

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer Certification at ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...