Splunk Search

Extract date and time

Devi13
Path Finder

Hello Team,

I need help in extracting the following date and time from the log,
sample log: -0900, 04.25.01 THU 22FEB24 nDD62320I

I need the 04.25.01 THU 22FEB24 part, could someone please help in extracting this using rex

Any help is much appreciated

Labels (2)
0 Karma
1 Solution

jotne
Builder

Some like this:

 

,\s(\d\d\.\d\d\.\d\d\s\w+\s\d+\w+\d\d)\s

 

Or do you like to do it props.conf to set the _time field?

TIME_FORMAT =  %z, %T %a %d%b%y

Try it out here: https://strftime.net/

View solution in original post

0 Karma

jotne
Builder

Some like this:

 

,\s(\d\d\.\d\d\.\d\d\s\w+\s\d+\w+\d\d)\s

 

Or do you like to do it props.conf to set the _time field?

TIME_FORMAT =  %z, %T %a %d%b%y

Try it out here: https://strftime.net/

0 Karma

Devi13
Path Finder

hii, 

it worked fine till February but for some reason the date is not getting extracted for March.

Could you please help here

want the date extracted for all the months..as the day goes by

0 Karma

jotne
Builder

I guess the first 9 days in every month has just one digit.  This should do:

 

,\s(\d\d\.\d\d\.\d\d\s\w+\s+\d+\w+\d\d)\s

 

Added a + behind a space since it may be more than one space

TIME_FORMAT =  %z, %T %a %e%b%y

Change a %d to %e

0 Karma

isoutamo
SplunkTrust
SplunkTrust

Hi

as @jotne has used %z as time zone information on props.conf you should add also this to your regex and then if/when needed use strptime and strftime functions to convert that field as needed. On ingestion time that happened automatically with correct TIME* definitions.

r. Ismo

0 Karma

Devi13
Path Finder

Thank you so much for your great help 🙂

0 Karma

Devi13
Path Finder

Hello @jotne ,

this is the regex: | rex field=_raw (?<date>\s(\d\d\.\d\d\.\d\d\s\w+\s\d+\w+\d\d)\s) 

0 Karma

Devi13
Path Finder
Thank you so much, worked like a charm
0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.
Get Updates on the Splunk Community!

Tech Talk Recap | Mastering Threat Hunting

Mastering Threat HuntingDive into the world of threat hunting, exploring the key differences between ...

Observability for AI Applications: Troubleshooting Latency

If you’re working with proprietary company data, you’re probably going to have a locally hosted LLM or many ...

Splunk AI Assistant for SPL vs. ChatGPT: Which One is Better?

In the age of AI, every tool promises to make our lives easier. From summarizing content to writing code, ...