Splunk Search

Replacing multiple values of a field with single value with rex sed

viswatejabolla
New Member

Hi All,

I have field called stepName which will have below three values.

TextResource.getFirstLine

TextResource.getSecondLine

TextResource.getLastLine

How can write a rex with mode=sed to replace only the words First,Second and Last from the stepName field to "Which", so that my output will have only one stepName field value as "TextResource.getWhichLine".

 

Labels (2)
0 Karma

richgalloway
SplunkTrust
SplunkTrust

This should do it.

| rex field=stepName mode=sed "s/(First|Second|Last)/Which/"
---
If this reply helps you, Karma would be appreciated.
0 Karma

viswatejabolla
New Member

Hi Rich,

Thanks for responding. Those are not the only three which I have. There are some other stepNames as well which have same starting string and ending string. Adding all of those words to the search string will make it ugly.

Anything can be done like "startswith" and "endwith", or by a regex which can do this without giving all the words.

0 Karma

richgalloway
SplunkTrust
SplunkTrust
| rex field=data mode=sed "s/(TextResource\.get).*(Line)/\1Which\2/"
---
If this reply helps you, Karma would be appreciated.
0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...