Dashboards & Visualizations

How to extract Date and Time from the raw logs

aditsss
Motivator

Hi Everyone,

Below is my data( raw logs)

pod_name=node-fdzz message=2020-09-25 21:09:33.969 ERROR [node,00e,4deca,false]67 --- [r-84-548] c.r.Resolver 

How do I extract Date and time 2020-09-25 21:09:33.969 from the above log data?

Can anyone guide me on this.

Labels (2)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust
index=abc ns=sigh nodeException node="*" Id=* |rex "message=(?P<datetime>\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}\.\d+)\s"|fields datetime

You don't need field= as the default field is _raw - if you want to specify it explicitly then use

index=abc ns=sigh nodeException node="*" Id=* |rex field=_raw "message=(?P<datetime>\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}\.\d+)\s"|fields datetime

View solution in original post

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

This regex will extract the datetime

"message=(?P<datetime>\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}\.\d+)\s"
0 Karma

aditsss
Motivator

@ITWhisperer 

 

I tried like below . Not able to get any result

Where I am going wrong!

index=abc ns=sigh nodeException node="*" Id=* |rex field="message=(?P<datetime>\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}\.\d+)\s"|fields datetime

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Ideally, this extract should be done at indexing time

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust
index=abc ns=sigh nodeException node="*" Id=* |rex "message=(?P<datetime>\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}\.\d+)\s"|fields datetime

You don't need field= as the default field is _raw - if you want to specify it explicitly then use

index=abc ns=sigh nodeException node="*" Id=* |rex field=_raw "message=(?P<datetime>\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}\.\d+)\s"|fields datetime
0 Karma

aditsss
Motivator

@ITWhisperer 

 

Thank you once again . It works exactly the way I want.

0 Karma
Get Updates on the Splunk Community!

Splunk Decoded: Service Maps vs Service Analyzer Tree View vs Flow Maps

It’s Monday morning, and your phone is buzzing with alert escalations – your customer-facing portal is running ...

What’s New in Splunk Observability – September 2025

What's NewWe are excited to announce the latest enhancements to Splunk Observability, designed to help ITOps ...

Fun with Regular Expression - multiples of nine

Fun with Regular Expression - multiples of nineThis challenge was first posted on Slack #regex channel ...