Splunk Search

How to replace Unique Values?

mcscjlf
Explorer

Hello, 

I have several events in the _raw field that add a unique identification number. I would like to replace these with something standard to aggregate counts on. 

Example Data:

fi/transaction/card/purchase/tx_2994882028948/refund

fi/transaction/card/purchase/tx_3920496893002/void

fi/transaction/card/purchase/tx_2930540482198/refund

 

I'd like these all to read: 

fi/transaction/card/purchase/trans/refund

fi/transaction/card/purchase/trans/void

fi/transaction/card/purchase/trans/refund

 

So replace the unique identifier, but maintain the verbiage at the end. 

I've tried a few of the other methods noted in other threads, but to no avail. Some don't work at all, some run, but don't replace the values.

Thanks!!

Labels (2)
Tags (1)
0 Karma

mcscjlf
Explorer

Thanks for the suggestions! Unfortunately, neither worked. I am trying to change this data in the search and only for the search results, I don't want to permanently change the underlying data. Perhaps my other search criteria is affecting the results with the solutions provided. 

Search Criteria:

host="Example"  sourcetype=Hexflag2  /fi/transaction/* | rex "POST (?<transact>/S+)" | stats county by transact

This returns the example data below, I'm just hoping for a way to condense all of the unique values to something I can rollup into a usage count.

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Firstly, rex mode=sed doesn't change the underlying data permanently, it just modifies the events in the event pipeline.

It looks like I missed a slash out - try this

host="Example"  sourcetype=Hexflag2  /fi/transaction/*
| rex mode=sed "s/\/tx_\d+\//\/trans\//g"
| rex "POST (?<transact>/\S+)" 
| stats count by transact

danielcj
Communicator

Hello @mcscjlf ,
You could try something like that (assuming that you want to see this data in search-time):

| rex mode=sed field=_raw "s/(\S+)(tx_\S+)(\/\S+)/\1trans\3/g"

 

You can change the field=_raw to your specific field, if it is being extracted already in a field.

ITWhisperer
SplunkTrust
SplunkTrust

If your unique identification number match a common pattern, then you can you rex in sed mode

| rex mode=sed "s/\/tx_\d+\/\/trans\//g"

 

0 Karma
Get Updates on the Splunk Community!

Accelerating Observability as Code with the Splunk AI Assistant

We’ve seen in previous posts what Observability as Code (OaC) is and how it’s now essential for managing ...

Integrating Splunk Search API and Quarto to Create Reproducible Investigation ...

 Splunk is More Than Just the Web Console For Digital Forensics and Incident Response (DFIR) practitioners, ...

Congratulations to the 2025-2026 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...