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!

Announcing Scheduled Export GA for Dashboard Studio

We're excited to announce the general availability of Scheduled Export for Dashboard Studio. Starting in ...

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics GA in US-AWS!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...