Splunk Search

Getting Time of last occurrence of a sbstring

siddharthmis
Explorer

I have events like below in a log file-

06/18/2017 22:35:10,Message="Finished Cleanup"
06/18/2017 22:57:02,Message="Finished Cleanup"
06/18/2017 22:57:02,Message="Finished Cleanup"

I want to extract (only) the time "06/18/2017 22:57" i.e. the time of last occurrence.

I used-

source="**"  Message="Finished Cleanup" |  stats max(_time) as time by Message  | eval End_Time=strftime(time,"%m/%d/%Y %H:%M")

But stats is not helping as I only want the time stamp.
How can I get time stamp only.

Tags (2)
0 Karma

inventsekar
SplunkTrust
SplunkTrust

Hi siddharthmis, may we know if this is working fine now? can you please mark this as completed

0 Karma

inventsekar
SplunkTrust
SplunkTrust

maybe, try - tail 1 --- to get the oldest event and then a rex to extract the timestamp.

( "tail 1" worked the opposite way around, replace it with "head 1" )

source="**" Message="Finished Cleanup" | tail 1 | rex field=_raw "^(?<DateTime>\d+\/\d+\/\d+\s+\d+:\d+:\d+)" | table DateTime _raw

0 Karma

dineshraj9
Builder

You are filtering out based on the Message field, so you don't need to use it with stats command -

 source="**"  Message="Finished Cleanup" |  stats max(_time) as time | eval End_Time=strftime(time,"%m/%d/%Y %T")

Also you are filter fields using the fields command.

http://docs.splunk.com/Documentation/SplunkCloud/6.6.0/SearchReference/Fields

0 Karma
Get Updates on the Splunk Community!

Your Guide to SPL2 at .conf24!

So, you’re headed to .conf24? You’re in for a good time. Las Vegas weather is just *chef’s kiss* beautiful in ...

Get ready to show some Splunk Certification swagger at .conf24!

Dive into the deep end of data by earning a Splunk Certification at .conf24. We're enticing you again this ...

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

Now On-Demand Join us to learn more about how you can leverage Service Level Objectives (SLOs) and the new ...