Splunk Search

Replacing a field value which is present in another field using rex sed command

akil8295
New Member

Hi All,

I am trying to replace values which are already fields present in another field using rex and mode = sed.

 Example I have two fields ID and error and both of them are Dynamic and Unique. Some ID's are found in the error field.

Now I would like to replace the different ID's in the error field with a common String.

| rex field=error mode=sed "s/ID/ My Id/g"

If I type in a regular expression  it replaces a few but it is not very accurate and  that is why  I want to make use of the field which is Id itself.

However it is not able to replace. Kindly assist on how to do the same. Thank you!

Labels (2)
0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @akil8295,

did you explored the choice to use calculated fields or automatic lookups?

so id you have some ID values in the error field, you could create a calculated field like this:

| eval ID=if(match(error="%12345%","12345",ID)

in this way you can create an ID value using what you find in the rrror field.

If the are too many to manage with one or more evals, you can use an automatic lookup (https://docs.splunk.com/Documentation/Splunk/8.1.0/Knowledge/Makeyourlookupautomatic).

Ciao.

Giuseppe

0 Karma
Get Updates on the Splunk Community!

Index This | What is broken 80% of the time by February?

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

Unlock Faster Time-to-Value on Edge and Ingest Processor with New SPL2 Pipeline ...

Hello Splunk Community,   We're thrilled to share an exciting update that will help you manage your data more ...

Splunk MCP & Agentic AI: Machine Data Without Limits

Discover how the Splunk Model Context Protocol (MCP) Server can revolutionize the way your organization uses ...