Splunk Search

How do I extract the date from the file name itself

tkmads1
Explorer

I need to extract date from the log file name as my logs only have a timestamp and no date available.

The date format is:
xxx_06-20-15-xxx.trc

I have also tried to edit the following stanza in datetime.xml:

<define name="_masheddate" extract="year, month, day">
<text>
<[CDATA[ (?:^|source::).*?(?<!\d|\d\.|-)(?:20)?([901]\d)(0\d|1[012])([012]\d|3[01])(?!\d|-| {2,})
  ]]>
</text>
</define>

But I'm unable to get the required result.

How can I do it?

0 Karma

woodcock
Esteemed Legend

You must do this with datetime.xml; but you must NEVER edit the existing global file! You need to create your own, put an entry in your own app's props.conf (again, not the global one) file, like this:

DATETIME_CONFIG = /etc/apps/MyApp/default/datetime.xml

It should have something like this:

 <datetime>
 <define name="myappdatetimefromfile" extract="year, month, day">
    <text><![CDATA[source::.*?-(\d{2})(0\d|1[012])([012]\d|3[01])-\d{2}_\d{2}]]></text>
 </define>
 <timePatterns>
    <use name="myappdatetimefromfile"/>
 </timePatterns>
 <datePatterns>
    <use name="myappdatetimefromfile"/>
 </datePatterns>
 </datetime>
0 Karma
Get Updates on the Splunk Community!

Splunk Observability for AI

Don’t miss out on an exciting Tech Talk on Splunk Observability for AI!Discover how Splunk’s agentic AI ...

Splunk Enterprise Security 8.x: The Essential Upgrade for Threat Detection, ...

Watch On Demand the Tech Talk on November 6 at 11AM PT, and empower your SOC to reach new heights! Duration: ...

Splunk Observability as Code: From Zero to Dashboard

For the details on what Self-Service Observability and Observability as Code is, we have some awesome content ...