Splunk Search

Remove timestamps using regex

oliverpeloton23
Engager

Hi Splunk Community,

It's been a while since I've last used Splunk and regex, and now I'm struggling with both 🙂

Fields that I need to use ("resourceId") contain two user IDs and timestamps (e.g., "owner-10785-user-3801-key-1637099215"). I'm looking to keep the IDs and remove timestamps (basically everything after "owner-19803-user-8925-").

I came up with this clumsy thing:

index=main | eval resourceId1=replace (resourceId, "user-(?<user_id>\d+)", "") | eval resourceId2=replace (resourceId1, "owner-(?<owner_id>\d+)", "") | table resourceId2

It kind of works, the only problem is that it gives me the opposite result - it removes all the IDs leaving the timestamps, like this:

resourceId2
--key-1637100297
--1637100120.0929909
--key-1637100118

But I need the opposite. Can anyone please help?

Labels (1)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust
| rex field=resourceId "owner-(?<owner>\d+)-user-(?<user>\d+)"
| eval resourceId2="owner-".owner."-user-".user

View solution in original post

ITWhisperer
SplunkTrust
SplunkTrust
| rex field=resourceId "owner-(?<owner>\d+)-user-(?<user>\d+)"
| eval resourceId2="owner-".owner."-user-".user

oliverpeloton23
Engager

Thank you!

0 Karma
Get Updates on the Splunk Community!

See your relevant APM services, dashboards, and alerts in one place with the updated ...

As a Splunk Observability user, you have a lot of data you have to manage, prioritize, and troubleshoot on a ...

Index This | What goes away as soon as you talk about it?

May 2025 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with this month’s ...

What's New in Splunk Observability Cloud and Splunk AppDynamics - May 2025

This month, we’re delivering several new innovations in Splunk Observability Cloud and Splunk AppDynamics ...