Dashboards & Visualizations

How to replace the special characters with Space in text field in Dashboard

shraysharma88
New Member

I am looking for replacing "James:bond;sharma" with "James bond sharma"in text box in dashboard.

index=*  sourcetype=*  $Pattern$

The pattern is the token value for the Text box in Splunk Dashboard.
I want to replace all the special characters with space in token value while searching, as I don't want to search for special characters even if it is provided in text box in Splunk dashboard.

0 Karma

wmyersas
Builder

Here's one way you can do it:

| eval data=replace(data,"\W"," ")
| eval data=replace(data,"\ {2,}"," ")

That will remove any non-word characters, swapping for a space. Then replace any sequential spaces with a single space.

shraysharma88
New Member

index=TEST1 sourcetype=TEST2 |eval Patterns="VNRDUS33_:" | eval Pattern1 = upper(replace(Patterns,"([-:._])"," "))| return Pattern1 | search Pattern1

I am facing issue while trying to search the pattern now.
Replace is working as expected.

0 Karma

wmyersas
Builder

What are you using return for here?

0 Karma

mayurr98
Super Champion

Try rex to change replace special characters with space

| makeresults | eval data="James:bond;sharma"  | rex field=data mode=sed "s/(\w+)(:)(\w+)(;)(\w+)/\1 \3 \5/"
0 Karma

shraysharma88
New Member

James:bond;sharma is the input I have given in text box in dashboard.
And data in text box can be any thing like ram$shyam%hari.
I want to replace every special character with space.

Below is the search query for panel -:

index=* sourcetype=* $Pattern$

where Pattern is the token value used for text box in panel of dashboard

0 Karma

mayurr98
Super Champion

try this then

| rex field=data mode=sed "s/(\w+)([^\w]+)(\w+)([^\w]+)(\w+)/\1 \3 \5/"
this will replace any special character with space

0 Karma
Get Updates on the Splunk Community!

[Puzzles] Solve, Learn, Repeat: Dynamic formatting from XML events

This challenge was first posted on Slack #puzzles channelFor a previous puzzle, I needed a set of fixed-length ...

Enter the Agentic Era with Splunk AI Assistant for SPL 1.4

  🚀 Your data just got a serious AI upgrade — are you ready? Say hello to the Agentic Era with the ...

Stronger Security with Federated Search for S3, GCP SQL & Australian Threat ...

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...