Splunk Search

How to do 2 parameters rex mode=sed ?

pgbr7
Explorer

Hello Guys,

It's possible 2 parameters rex mode=sed in sequence ?
I can change ab for 01 and ac for 02

I try this, but not work:
| rex mode=sed field=_raw "s/ab/01/g;s/ac/02/g"
Error:
Error in 'rex' command: Failed to initialize sed. Invalid option string: g;s/ac/02/g

or i need to use 2 rex mode=sed field=_raw , 1 for change ab for 01and other for change ac for 02 ?

0 Karma
1 Solution

gokadroid
Motivator

Use the rex mode sed command split over two lines rather than writing the code in one single line. Also do not use the ; in between. So basically whatever you were trying to achieve with semicolon in between, achieve it with in same command but split over two lines:

yourBaseSearch
| rex mode=sed field=_raw "s/ab/01/g
s/ac/02/g"
| stats count by yourField

NOTE: I have removed the semicolon and tricked command to be in multiline

View solution in original post

gokadroid
Motivator

Use the rex mode sed command split over two lines rather than writing the code in one single line. Also do not use the ; in between. So basically whatever you were trying to achieve with semicolon in between, achieve it with in same command but split over two lines:

yourBaseSearch
| rex mode=sed field=_raw "s/ab/01/g
s/ac/02/g"
| stats count by yourField

NOTE: I have removed the semicolon and tricked command to be in multiline

pgbr7
Explorer

Thanks It's working !

redflexigork
Explorer

Also noticed it works with the space:

| rex mode=sed field=_raw "s/ab/01/g s/ac/02/g"

richgalloway
SplunkTrust
SplunkTrust

Use two rex commands.

---
If this reply helps you, Karma would be appreciated.
0 Karma

pgbr7
Explorer

This is not good, because if I need to change 3 or more its very dificult.

Thanks

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 ...