Splunk Search

How to extract filename from fields?

dhirendra761
Contributor

I am trying to extract a filename Nsences_2016_10_10_12_50.csv from below field value.

D:\Program Files\X620\ABC\TGF\Files\sss\Nsences_2016_10_10_12_50.csv Complete, status : 226 Transfer complete." 
| rex field=raw_field "D:\\(.+\\)*(?<filename>.*)\.csv Complete, status : 226 Transfer complete.

I am extracting as below.

| makeresults 
| eval raw_field="D:\Program Files\X620\ABC\TGF\Files\sss\Nsences_2016_10_10_12_50.csv Complete, status : 226 Transfer complete." 
| rex field=raw_field "D:\\(.+\\)*(?<filename>.*)\.csv Complete, status : 226 Transfer complete." 
| table raw_field filename

Please help me. Thanks in advance.

Dhirendra

0 Karma
1 Solution

harsmarvania57
Ultra Champion

Hi,

Please try below regex.

<yourBaseSearch>
| rex field=<yourfield> "\x5c(?<filename>[^\x5c]+\.[^\s]+)"

View solution in original post

vinod94
Contributor
| makeresults 
| eval date="D:\Program Files\X620\ABC\TGF\Files\sss\Nsences_2016_10_10_12_50.csv Complete, status : 226 Transfer complete." 
| rex field=date "\\\Files.*\\\(?P<filename>.+)\s\w+,"

dhirendra761
Contributor

Thank you for your answer @vinod94

0 Karma

harsmarvania57
Ultra Champion

Hi,

Please try below regex.

<yourBaseSearch>
| rex field=<yourfield> "\x5c(?<filename>[^\x5c]+\.[^\s]+)"

dhirendra761
Contributor

Thanks @harsmarvania57 for your answer 🙂

0 Karma

harsmarvania57
Ultra Champion

Welcome 🙂

0 Karma
Get Updates on the Splunk Community!

Strengthen Your Future: A Look Back at Splunk 10 Innovations and .conf25 Highlights!

The Big One: Splunk 10 is Here!  The moment many of you have been waiting for has arrived! We are thrilled to ...

Now Offering the AI Assistant Usage Dashboard in Cloud Monitoring Console

Today, we’re excited to announce the release of a brand new AI assistant usage dashboard in Cloud Monitoring ...

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

What are Community Office Hours? Community Office Hours is an interactive 60-minute Zoom series where ...