<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Replace Characters- How can I replace \\\\ for \ ? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Replace-Characters-How-can-I-replace-for/m-p/645479#M223494</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/257347"&gt;@Tincho&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;It can be a bit of a pain creating regexes inside quotes, because you have to escape characters for the string, and escape characters for regex - meaning you double up on escaping characters.&lt;BR /&gt;&lt;BR /&gt;Here's a search that takes &lt;EM&gt;domain\\\\user&lt;/EM&gt; and converts it to &lt;EM&gt;domain\user&lt;/EM&gt; in a couple of different ways:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults| eval user_name="DOMAIN\\\\\\\\USER"

``` Using replace - escaping multiple times ```
| eval user_name_replace=replace(user_name, "\\\\\\\\\\\\\\\\","\\")

``` Using sed ```
| eval user_name_sed = user_name
| rex field=user_name_sed mode=sed "s/\\\\{4}/\\\\/"

``` Using rex to create a domain field, and user field, then combining them ```
| rex field=user_name "^(?&amp;lt;domain&amp;gt;[^\\\\]+)\\\\+(?&amp;lt;user&amp;gt;.+)$"
| eval user_name_regex = domain . "\\" . user

``` output the results ```
| table user_name, user_name_replace,user_name_sed, user_name_regex&lt;/LI-CODE&gt;&lt;P&gt;That results in :&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="danspav_1-1685688194263.png" style="width: 999px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/25656i3BFCE48B7153E2F2/image-size/large?v=v2&amp;amp;px=999" role="button" title="danspav_1-1685688194263.png" alt="danspav_1-1685688194263.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Cheers,&lt;BR /&gt;Daniel&lt;/P&gt;</description>
    <pubDate>Fri, 02 Jun 2023 06:48:21 GMT</pubDate>
    <dc:creator>danspav</dc:creator>
    <dc:date>2023-06-02T06:48:21Z</dc:date>
    <item>
      <title>Replace Characters- How can I replace \\\\ for \ ?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Replace-Characters-How-can-I-replace-for/m-p/645450#M223481</link>
      <description>&lt;P&gt;Hi guys how are you doing?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm reading this link&amp;nbsp;&lt;A href="https://community.splunk.com/t5/Splunk-Search/How-to-use-replace-in-search/m-p/323386" target="_blank" rel="noopener"&gt;Solved: How to use replace in search? - Splunk Community&lt;/A&gt;&amp;nbsp;but I can't get results with what I want to do.&lt;/P&gt;
&lt;P&gt;From a search I get a field called "user_name" with the following format "DOMAIN\\\\USER" what I want to do is to replace \\\\ with only one \ and get "DOMAIN\USER"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I use the query that I saw i the link attached I get this error&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tincho_0-1685656301040.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/25649i5DC89D119551B87B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tincho_0-1685656301040.png" alt="Tincho_0-1685656301040.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I add one " I get this&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tincho_1-1685656499853.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/25650iEEB7718C5DA4058E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tincho_1-1685656499853.png" alt="Tincho_1-1685656499853.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How can I replace \\\\ for \ ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards.&lt;BR /&gt;Martín.&lt;/P&gt;</description>
      <pubDate>Fri, 02 Jun 2023 06:24:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Replace-Characters-How-can-I-replace-for/m-p/645450#M223481</guid>
      <dc:creator>Tincho</dc:creator>
      <dc:date>2023-06-02T06:24:03Z</dc:date>
    </item>
    <item>
      <title>Re: Replace Characters- How can I replace \\\\ for \ ?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Replace-Characters-How-can-I-replace-for/m-p/645479#M223494</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/257347"&gt;@Tincho&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;It can be a bit of a pain creating regexes inside quotes, because you have to escape characters for the string, and escape characters for regex - meaning you double up on escaping characters.&lt;BR /&gt;&lt;BR /&gt;Here's a search that takes &lt;EM&gt;domain\\\\user&lt;/EM&gt; and converts it to &lt;EM&gt;domain\user&lt;/EM&gt; in a couple of different ways:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults| eval user_name="DOMAIN\\\\\\\\USER"

``` Using replace - escaping multiple times ```
| eval user_name_replace=replace(user_name, "\\\\\\\\\\\\\\\\","\\")

``` Using sed ```
| eval user_name_sed = user_name
| rex field=user_name_sed mode=sed "s/\\\\{4}/\\\\/"

``` Using rex to create a domain field, and user field, then combining them ```
| rex field=user_name "^(?&amp;lt;domain&amp;gt;[^\\\\]+)\\\\+(?&amp;lt;user&amp;gt;.+)$"
| eval user_name_regex = domain . "\\" . user

``` output the results ```
| table user_name, user_name_replace,user_name_sed, user_name_regex&lt;/LI-CODE&gt;&lt;P&gt;That results in :&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="danspav_1-1685688194263.png" style="width: 999px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/25656i3BFCE48B7153E2F2/image-size/large?v=v2&amp;amp;px=999" role="button" title="danspav_1-1685688194263.png" alt="danspav_1-1685688194263.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Cheers,&lt;BR /&gt;Daniel&lt;/P&gt;</description>
      <pubDate>Fri, 02 Jun 2023 06:48:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Replace-Characters-How-can-I-replace-for/m-p/645479#M223494</guid>
      <dc:creator>danspav</dc:creator>
      <dc:date>2023-06-02T06:48:21Z</dc:date>
    </item>
    <item>
      <title>Re: Replace Characters- How can I replace \\\\ for \ ?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Replace-Characters-How-can-I-replace-for/m-p/645566#M223513</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/170645"&gt;@danspav&lt;/a&gt;&amp;nbsp;thanks a lot for your response.&lt;/P&gt;&lt;P&gt;I was able to replace DOMAIN\\\\USER for DOMAIN\USER with the regex option.&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":grinning_face:"&gt;😀&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Jun 2023 14:29:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Replace-Characters-How-can-I-replace-for/m-p/645566#M223513</guid>
      <dc:creator>Tincho</dc:creator>
      <dc:date>2023-06-02T14:29:18Z</dc:date>
    </item>
    <item>
      <title>Re: Replace Characters- How can I replace \\\\ for \ ?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Replace-Characters-How-can-I-replace-for/m-p/645645#M223544</link>
      <description>&lt;P&gt;In case you are counting the proliferation of backslashes, here is a slightly less painful one:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval user_name = mvjoin(split(user_name, "\\\\\\\\"), "\\")&lt;/LI-CODE&gt;&lt;P&gt;Another one using sed&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| rex field=user_name mode=sed "s/\\\+/\\\/"&lt;/LI-CODE&gt;&lt;P&gt;And finally, using replace&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval user_name = replace(user_name, "\\\+", "\\")&lt;/LI-CODE&gt;</description>
      <pubDate>Sun, 04 Jun 2023 01:17:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Replace-Characters-How-can-I-replace-for/m-p/645645#M223544</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2023-06-04T01:17:36Z</dc:date>
    </item>
  </channel>
</rss>

