Splunk Search

eval to handle 2 scenarios

Raj_Splunk_Ing
Path Finder

Hi, I have this field in this format and i am using eval to convert but sometimes there is an extra space in it

after : 

Mon 2 Jun 2025 20:51:24 : 792 EDT  - with extra space after hhmmss (space before 792)

Mon 2 Jun 2025 20:51:24 :792 EDT - this is another scenario where there will be no space

i have to get 2 scenarios in this eval - any help
| eval date_only=strftime(strptime(ClintReqRcvdTime, "%a %d %b %Y %H:%M:%S :%3N %Z"), "%m/%d/%Y")

 

Labels (1)
0 Karma
1 Solution

richgalloway
SplunkTrust
SplunkTrust

Yes, this covers both cases.  If the extra space is not present then sed does nothing.

---
If this reply helps you, Karma would be appreciated.

View solution in original post

richgalloway
SplunkTrust
SplunkTrust

Try using sed to normalize the data before conversion.

| rex mode=sed field=ClintReqRcvdTime "s/: /:/"
| eval date_only=strftime(strptime(ClintReqRcvdTime, "%a %d %b %Y %H:%M:%S :%3N %Z"), "%m/%d/%Y")

 

---
If this reply helps you, Karma would be appreciated.
0 Karma

Raj_Splunk_Ing
Path Finder

Rich, this is working too; it will cover both scenarios right? when there is no extra space in it?

0 Karma

richgalloway
SplunkTrust
SplunkTrust

Yes, this covers both cases.  If the extra space is not present then sed does nothing.

---
If this reply helps you, Karma would be appreciated.

Raj_Splunk_Ing
Path Finder

hi Rich, is reg much better than replace.. in my case looks like replace is working

0 Karma

sainag_splunk
Splunk Employee
Splunk Employee

@Raj_Splunk_Ing  try 

| eval date_only=strftime(strptime(replace(ClintReqRcvdTime, "\s+", " "), "%a %d %b %Y %H:%M:%S :%N EDT"), "%m/%d/%Y")
If this helps, Upvote!!!!
Together we make the Splunk Community stronger 

Raj_Splunk_Ing
Path Finder

Hi, Sai, sometimes i dont get the extra space so i have to cover 2 scenarios

will this only work when there is an extra space or it should take care of it when there is no extra space also

as we are specifying the extra space in the format and removing

0 Karma

Raj_Splunk_Ing
Path Finder

tried trim(field) but it not help

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!

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, ...

Data Persistence in the OpenTelemetry Collector

This blog post is part of an ongoing series on OpenTelemetry. What happens if the OpenTelemetry collector ...

Thanks for the Memories! Splunk University, .conf25, and our Community

Thank you to everyone in the Splunk Community who joined us for .conf25, which kicked off with our iconic ...