Splunk Search

extract date from string

sravanthikand
New Member

Hello

I have string from nessus . Wed Jun 6 02:02:10 2018 .

I need to extract the date . strftime and strptime returns NULL.

Any ideas for rex extraction ?

I need to compare and sort the date for the last 45 days .

Thanks

Tags (1)
0 Karma

woodcock
Esteemed Legend

Along with the answer from @mus, you need to make sure that you have a field myTime first. You create one like this:

| rex "(?<myTime>(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun)\s+\S+\d+\s+\d+:\d+:\d+\s+\d+)"

MuS
Legend

Hi sravanthikand,

try this strptime() format:

| makeresults 
| eval myTime="Wed Jun 6 02:02:10 2018" 
| eval epoch_time=strptime(myTime, "%c") 
| eval _time=epoch_time

This will create a valid epoch timestamp.

alt text

Hope this helps ...

cheers, MuS

Get Updates on the Splunk Community!

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!

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

New in Observability Cloud - Explicit Bucket Histograms

Splunk introduces native support for histograms as a metric data type within Observability Cloud with Explicit ...