Splunk Search

Modify a date field value using SED

jason_hotchkiss
Communicator

I have a weird date/time value:  20240307105530.358753-360

I would like to make it more user friendly  2024/03/07 10:50:30 and drop the rest.
%Y/%m/%d %H:%M:%S

I know you can use sed for this, however, I am not familiar with sed syntax:

For example:
| rex mode=sed field=_raw "s//g"

Any sed guru's out there?

Labels (2)
0 Karma
1 Solution

marnall
Builder

You can indeed do this with sed and rex:


| rex mode=sed field=<yourfield> "s/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2}).*/\1\/\2\/\3 \4:\5:\6/"

 

Every captured group in the first part of the sed can be referenced with a backslash+groupnumber. E.g: "\1" for group 1, "\2" for group 2. Everything not captured can be discarded. Forward slashes need to be escaped.

View solution in original post

marnall
Builder

You can indeed do this with sed and rex:


| rex mode=sed field=<yourfield> "s/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2}).*/\1\/\2\/\3 \4:\5:\6/"

 

Every captured group in the first part of the sed can be referenced with a backslash+groupnumber. E.g: "\1" for group 1, "\2" for group 2. Everything not captured can be discarded. Forward slashes need to be escaped.

jason_hotchkiss
Communicator

Thank you @marnall.  You are the master!

0 Karma

marnall
Builder

Glad to help 🙂

0 Karma
Get Updates on the Splunk Community!

Index This | I’m short for "configuration file.” What am I?

May 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with a Special ...

New Articles from Academic Learning Partners, Help Expand Lantern’s Use Case Library, ...

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

Your Guide to SPL2 at .conf24!

So, you’re headed to .conf24? You’re in for a good time. Las Vegas weather is just *chef’s kiss* beautiful in ...