Splunk Search

regex to get only the filename and filedate

surekhasplunk
Communicator

Hi,

My requirement is to show the date when the index got last created or to show the date of the latest file whose data is shown in the dashboard. How can i do that.

My index=bla source="D:\path1\dir1\data_19042018.csv"

i want to extract only the filename into a field filename using rex and also just the date it got indexed that is 19042018 into a field named indexed_date.

How to achieve this

Tags (3)
0 Karma
1 Solution

gcusello
SplunkTrust
SplunkTrust

Hi surekhasplunk,
try regexes like these:

My_index=bla source="D:\\path1\\dir1\\data_19042018.csv"
| rex field=source "\\(?<filename>\w*\.csv)"
| rex field=source "(?<filename>\d*)\.csv"

as you can test at https://regex101.com/r/ifSjOE/1

Bye.
Giuseppe

View solution in original post

0 Karma

p_gurav
Champion

Can you try:

| rex field=source "\\(?<filename>\w*\.csv)" 
|rex field=source "\\\w*_(?<indexed_date>[^\.]+)\.csv"
0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi surekhasplunk,
try regexes like these:

My_index=bla source="D:\\path1\\dir1\\data_19042018.csv"
| rex field=source "\\(?<filename>\w*\.csv)"
| rex field=source "(?<filename>\d*)\.csv"

as you can test at https://regex101.com/r/ifSjOE/1

Bye.
Giuseppe

0 Karma
Get Updates on the Splunk Community!

Fastest way to demo Observability

I’ve been having a lot of fun learning about Kubernetes and Observability. I set myself an interesting ...

September Community Champions: A Shoutout to Our Contributors!

As we close the books on another fantastic month, we want to take a moment to celebrate the people who are the ...

Splunk Decoded: Service Maps vs Service Analyzer Tree View vs Flow Maps

It’s Monday morning, and your phone is buzzing with alert escalations – your customer-facing portal is running ...