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!

SOCin’ it to you at Splunk University

Splunk University is expanding its instructor-led learning portfolio with dedicated Security tracks at .conf25 ...

Credit Card Data Protection & PCI Compliance with Splunk Edge Processor

Organizations handling credit card transactions know that PCI DSS compliance is both critical and complex. The ...

Stay Connected: Your Guide to July Tech Talks, Office Hours, and Webinars!

What are Community Office Hours?Community Office Hours is an interactive 60-minute Zoom series where ...