Splunk Search

How to remove all non-ascii character from search results?

ccloutralex
Observer

I have a fairly large(3,400 records) search result that randomly contains non-ascii characters in any one of the 20 fields. This normally is not an issue but the sendemail.py script that is used by splunks email alerting system is erroring out because of it. Is there a way to remove non-ascii characters from all search results? See below for search example:

 

 

| inputlookup StatusReport.csv | fields Name ID BusinessGroup Class Email Issues Comments Dynamic Status Owner HoB | sort ID

 

Labels (1)
Tags (1)
0 Karma

VatsalJagani
SplunkTrust
SplunkTrust

@ccloutralex - Can you please try below search?

| inputlookup StatusReport.csv | fields Name ID BusinessGroup Class Email Issues Comments Dynamic Status Owner HoB | sort ID
| foreach * [| rex field="<<FIELD>>" mode=sed "s/[^\x00-\x7F]/ /g"]

This will replace any non-ascii character with space.

 

I hope this helps. If it does consider upvoting!!

Gr0und_Z3r0
Contributor

Hi @ccloutralex 
If you know the fields that have non-ascii characters, try to replace them using sed command.

| rex mode=sed field=<fieldname> "s/<whatyouwannachange>/<whatitshouldbeafterwards>/g"

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Can’t Make It to Boston? Stream .conf25 and Learn with Haya Husain

Boston may be buzzing this September with Splunk University and .conf25, but you don’t have to pack a bag to ...

Splunk Lantern’s Guide to The Most Popular .conf25 Sessions

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

Unlock What’s Next: The Splunk Cloud Platform at .conf25

In just a few days, Boston will be buzzing as the Splunk team and thousands of community members come together ...