Splunk Search

How do you remove specific special characters from a field value?

RonWonkers
Path Finder

Hi, I have a field called "Employee_Email". This field contains the value:

["firstname.lastname@gmail.com"]

How do I remove the special characters [" and "]?

 

I tried: 

| eval test1 = replace (Employee_Email "[" , "")

 

But when I tried to remove either [ or " it gives me the following errors:

Error in 'EvalCommand': Regex: missing terminating ] for character class

Or:

Unbalanced quotes.

 

Is there a way to ignore the normal effect of [ and "?

Labels (6)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust

You need to escape the square brackets and double quotes

| eval test1=replace(replace(Employee_Email,"\[\"",""),"\"\]","")

View solution in original post

ITWhisperer
SplunkTrust
SplunkTrust

You need to escape the square brackets and double quotes

| eval test1=replace(replace(Employee_Email,"\[\"",""),"\"\]","")

RonWonkers
Path Finder

Tried this and it worked thanks

0 Karma

PickleRick
SplunkTrust
SplunkTrust

As an alternative you can use other functions

| eval trimmed_email=trim(Employee_Email,"\"[]")

or

| eval substr_email=substr(Employee_Email,3,len(Employee_Email)-4)

RonWonkers
Path Finder

This is indeed a nice alternative thank you!

0 Karma

RonWonkers
Path Finder

Edit:

I tried: 

| eval test1 = replace (Employee_Email, "[" , "")
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 ...