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!

Take Action Automatically on Splunk Alerts with Red Hat Ansible Automation Platform

 Are you ready to revolutionize your IT operations? As digital transformation accelerates, the demand for ...

Calling All Security Pros: Ready to Race Through Boston?

Hey Splunkers, .conf25 is heading to Boston and we’re kicking things off with something bold, competitive, and ...

Beyond Detection: How Splunk and Cisco Integrated Security Platforms Transform ...

Financial services organizations face an impossible equation: maintain 99.9% uptime for mission-critical ...