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!

October Community Champions: A Shoutout to Our Contributors!

As October comes to a close, we want to take a moment to celebrate the people who make the Splunk Community ...

Community Content Calendar, November Edition

Welcome to the November edition of our Community Spotlight! Each month, we dive into the Splunk Community to ...

Stay Connected: Your Guide to November Tech Talks, Office Hours, and Webinars!

What are Community Office Hours? Community Office Hours is an interactive 60-minute Zoom series where ...