Splunk Search

To findout month and week from a Field

kml_uvce
Builder

I have a field like in this format 2012-02-11
This field is in many events with diffrent year-month-day.

I want to make a search in which I can extaract information wrt month and week from this field.
How I can do this

Tags (2)
0 Karma
1 Solution

Ayn
Legend
... | rex field=yourfield "(?<year>.+?)-(?<month>.+?)-(?<day>.+)"

Substitute yourfield with whatever your field is called.

View solution in original post

Ayn
Legend
... | rex field=yourfield "(?<year>.+?)-(?<month>.+?)-(?<day>.+)"

Substitute yourfield with whatever your field is called.

Ayn
Legend

Excellent. Could you please mark my answer as accepted? Thanks!

0 Karma

kml_uvce
Builder

Thanks this works for me now...

0 Karma

Ayn
Legend

With all due respect: http://lmgtfy.com/?q=strftime

0 Karma

kml_uvce
Builder

I am not able to find out the complete doc for strftime, can you make this search ?

0 Karma

Ayn
Legend

Yes, using the same technique. Look up all strftime parameters, there are many different ones.

0 Karma

kml_uvce
Builder

cool it works , also is there any way to find month name also (jan ,feb etc) form search?

0 Karma

Ayn
Legend

Correcting myself - apparently strftime can handle this, using the %u (week starting on Monday) or %U (week starting on Sunday) parameter!

You could do something like this to get the week number:

eval week=strftime(strptime(yourfield,"%Y-%m-%d"),"%U")
0 Karma

kml_uvce
Builder

I mean to say that I want week number from this search so that I can make chart wrt week number

0 Karma

Ayn
Legend

Not easily done, as that will change from year to year. Your best bet would probably be to create a lookup file that maps dates to week numbers and use that.

0 Karma

kml_uvce
Builder

yes, its week number

0 Karma

Ayn
Legend

What do you mean by week, week number?

0 Karma

kml_uvce
Builder

ok it works for month , but how I can figure out about the week

0 Karma
Get Updates on the Splunk Community!

Routing logs with Splunk OTel Collector for Kubernetes

The Splunk Distribution of the OpenTelemetry (OTel) Collector is a product that provides a way to ingest ...

Welcome to the Splunk Community!

(view in My Videos) We're so glad you're here! The Splunk Community is place to connect, learn, give back, and ...

Tech Talk | Elevating Digital Service Excellence: The Synergy of Splunk RUM & APM

Elevating Digital Service Excellence: The Synergy of Real User Monitoring and Application Performance ...