Splunk Search

Remove words from a String

sebafdez
Explorer

Hi guys!

I need to remove words from 2 char in a string, I have a field like:

comment="La pagina web es muy mala demasiado lenta"

and I want it to be like:

new_comment="pagina web muy mala demasiado lenta"

where words of 2 char doesn't exist anymore, any idea how to implement this in SPL?

regards

Tags (1)
0 Karma
1 Solution

woodcock
Esteemed Legend

Like this:

...  | rex field=comment mode=sed "s/ .. / /g s/^.. //g s/ ..$//g"

View solution in original post

0 Karma

somesoni2
Revered Legend

Give this a try (Run anywhere sample search, replace line 1 with your search)

| gentimes start=-1 | eval comment="La pagina web es muy mala demasiado lenta 1 12 123 44" | table comment 
| eval new_comment=replace(comment,"(^|\s)(\w\w)(\s|$)","\1")
0 Karma

woodcock
Esteemed Legend

Like this:

...  | rex field=comment mode=sed "s/ .. / /g s/^.. //g s/ ..$//g"
0 Karma

sebafdez
Explorer

thanks! works great!

0 Karma
Get Updates on the Splunk Community!

Purpose in Action: How Splunk Is Helping Power an Inclusive Future for All

At Cisco, purpose isn’t a tagline—it’s a commitment. Cisco’s FY25 Purpose Report outlines how the company is ...

[Upcoming Webinar] Demo Day: Transforming IT Operations with Splunk

Join us for a live Demo Day at the Cisco Store on January 21st 10:00am - 11:00am PST In the fast-paced world ...

New Year. New Skills. New Course Releases from Splunk Education

A new year often inspires reflection—and reinvention. Whether your goals include strengthening your security ...