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!

Community Content Calendar, September edition

Welcome to another insightful post from our Community Content Calendar! We're thrilled to continue bringing ...

Splunkbase Unveils New App Listing Management Public Preview

Splunkbase Unveils New App Listing Management Public PreviewWe're thrilled to announce the public preview of ...

Leveraging Automated Threat Analysis Across the Splunk Ecosystem

Are you leveraging automation to its fullest potential in your threat detection strategy?Our upcoming Security ...