Splunk Search

how to replace \ with \\ in eval statement

reney44
Engager

i expect var1="d:\test\data.csv" but i got

it shows mismatch or missing closing parenthesis

var="d:\test\data.csv"
|eval var1=replace(var,"\","\\")

Tags (2)
0 Karma
1 Solution

javiergn
Super Champion

If all you are trying to do is to replace one backslash with two then you can do the following:

| stats count
| eval var="d:\\test\\data.csv"
| eval var1=replace(var,"\\\\","\\\\\\")

(Ignore the stats count as I used this to test)
Output:

alt text

Take a look at the following links if you want to read more about it:

https://docs.splunk.com/Documentation/Splunk/latest/Search/SPLandregularexpressions#Backslash_charac...
https://answers.splunk.com/answers/623193/tricky-behavior-of-escaping-backslash-in-regex.html#answer...

Regards,
J

View solution in original post

0 Karma

javiergn
Super Champion

If all you are trying to do is to replace one backslash with two then you can do the following:

| stats count
| eval var="d:\\test\\data.csv"
| eval var1=replace(var,"\\\\","\\\\\\")

(Ignore the stats count as I used this to test)
Output:

alt text

Take a look at the following links if you want to read more about it:

https://docs.splunk.com/Documentation/Splunk/latest/Search/SPLandregularexpressions#Backslash_charac...
https://answers.splunk.com/answers/623193/tricky-behavior-of-escaping-backslash-in-regex.html#answer...

Regards,
J

0 Karma

p_gurav
Champion
0 Karma
Get Updates on the Splunk Community!

Say goodbye to manually analyzing phishing and malware threats with Splunk Attack ...

In today’s evolving threat landscape, we understand you’re constantly bombarded with phishing and malware ...

AppDynamics is now part of Splunk Ideas

Hello Splunkers, We have exciting news for you! AppDynamics has been added to the Splunk Ideas Portal. Which ...

Advanced Splunk Data Management Strategies

Join us on Wednesday, May 14, 2025, at 11 AM PDT / 2 PM EDT for an exclusive Tech Talk that delves into ...