Splunk Search

How do I get a substring from a field after the "_" character?

vb1612
New Member

I have a string as ABCD_20190219_XYZ

I need to get 20190219 like 8 characters after first "_" and than convert that substring to a date.

Thanks

Tags (3)
0 Karma
1 Solution

Vijeta
Influencer

You can use rex to get the date substring and then use strptime and strftime to date format. Suppose your string is x="ABCD_20190219_XYZ", then use the below command.

rex field=x "_(?<date>\S{8})"| eval time=strptime(date,"%Y%m%d")|eval Date=strftime(time,"%m/%d/%Y")

View solution in original post

0 Karma

Vijeta
Influencer

You can use rex to get the date substring and then use strptime and strftime to date format. Suppose your string is x="ABCD_20190219_XYZ", then use the below command.

rex field=x "_(?<date>\S{8})"| eval time=strptime(date,"%Y%m%d")|eval Date=strftime(time,"%m/%d/%Y")
0 Karma
Get Updates on the Splunk Community!

Webinar Recap | Revolutionizing IT Operations: The Transformative Power of AI and ML ...

The Transformative Power of AI and ML in Enhancing Observability   In the realm of IT operations, the ...

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...