<?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 strings in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-replace-replace-strings/m-p/655312#M226379</link>
    <description>&lt;P&gt;I tried:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;| makeresults count=10&lt;BR /&gt;| eval src=random().".wxyz.com"&lt;BR /&gt;| eval name = replace(src,".wxyz.com", ".abc.com")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To see how it worked.&lt;/P&gt;</description>
    <pubDate>Wed, 23 Aug 2023 11:48:50 GMT</pubDate>
    <dc:creator>neo3779_splunk</dc:creator>
    <dc:date>2023-08-23T11:48:50Z</dc:date>
    <item>
      <title>How to replace replace strings?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-replace-replace-strings/m-p/327786#M97568</link>
      <description>&lt;P&gt;Hello,&lt;BR /&gt;I have a lookup file with data in following format&lt;/P&gt;
&lt;P&gt;name _time&lt;BR /&gt;srv-a.xyz.com 2017.07.23&lt;BR /&gt;srv-b.wxyz.com 2017.07.23&lt;/P&gt;
&lt;P&gt;I want to replace .xyz.com with wxyz.com&lt;/P&gt;
&lt;P&gt;My replace query does this correctly for values which end with .xyz.com. However for values ending with .wxyz.com it adds an extra . (dot) to the result.&lt;/P&gt;
&lt;P&gt;| eval name = replace(name,".xyz.com", ".wxyz.com")&lt;BR /&gt;So the final output looks like :&lt;/P&gt;
&lt;P&gt;name _time&lt;BR /&gt;srv-a.wxyz.com 2017.07.23&lt;BR /&gt;srv-b..wxyz.com 2017.07.23&lt;/P&gt;
&lt;P&gt;why is that ? Any help on this highly appreciated. Thanks&lt;/P&gt;</description>
      <pubDate>Wed, 23 Aug 2023 19:23:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-replace-replace-strings/m-p/327786#M97568</guid>
      <dc:creator>saurabhkunte</dc:creator>
      <dc:date>2023-08-23T19:23:04Z</dc:date>
    </item>
    <item>
      <title>Re: replace strings</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-replace-replace-strings/m-p/327787#M97569</link>
      <description>&lt;P&gt;The &lt;CODE&gt;replace&lt;/CODE&gt; function actually is regex.  From the &lt;A href="http://docs.splunk.com/Documentation/SplunkCloud/6.6.0/SearchReference/TextFunctions#replace.28X.2CY.2CZ.29"&gt;most excellent docs on replace&lt;/A&gt;:&lt;/P&gt;

&lt;P&gt;replace(X,Y,Z) - This function returns a string formed by substituting string Z for every occurrence of regex string Y in string X. The third argument Z can also reference groups that are matched in the regex. &lt;/P&gt;

&lt;P&gt;The &lt;CODE&gt;X&lt;/CODE&gt; and &lt;CODE&gt;Z&lt;/CODE&gt; portions are just strings, so in there a period is just a period, right?&lt;BR /&gt;
The &lt;CODE&gt;Y&lt;/CODE&gt; is a REGEX, and regular expressions use the dot as a wildcard for "any single character".&lt;/P&gt;

&lt;P&gt;That means in &lt;CODE&gt;replace(name,".xyz.com", ".wxyz.com")&lt;/CODE&gt; you are replacing every occurance of &lt;CODE&gt;&amp;lt;any single character&amp;gt;xyz&amp;lt;any single character&amp;gt;com&lt;/CODE&gt; with ".wxyz.com".&lt;/P&gt;

&lt;P&gt;If you want to use replace with literally what you wrote, just escape the periods by putting a backslash in front of them.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval name = replace(name,"\.xyz\.com", ".wxyz.com")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Here's a run-anywhere with it fixed.  To watch it not work right, just remove the backslashes!&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval src=".wxyz.com"
| eval name = replace(src,"\.xyz\.com", ".wxyz.com")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Happy Splunking!&lt;BR /&gt;
-Rich&lt;/P&gt;</description>
      <pubDate>Sun, 23 Jul 2017 12:17:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-replace-replace-strings/m-p/327787#M97569</guid>
      <dc:creator>Richfez</dc:creator>
      <dc:date>2017-07-23T12:17:56Z</dc:date>
    </item>
    <item>
      <title>Re: replace strings</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-replace-replace-strings/m-p/327788#M97570</link>
      <description>&lt;P&gt;You can try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| replace "*.xyz.com" with "*.wxyz.com" in name
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 23 Jul 2017 19:13:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-replace-replace-strings/m-p/327788#M97570</guid>
      <dc:creator>cmerriman</dc:creator>
      <dc:date>2017-07-23T19:13:27Z</dc:date>
    </item>
    <item>
      <title>Re: replace strings</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-replace-replace-strings/m-p/327789#M97571</link>
      <description>&lt;P&gt;Thank you Rich ! I overlooked the wildcard for any single character. &lt;/P&gt;</description>
      <pubDate>Mon, 24 Jul 2017 07:05:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-replace-replace-strings/m-p/327789#M97571</guid>
      <dc:creator>saurabhkunte</dc:creator>
      <dc:date>2017-07-24T07:05:42Z</dc:date>
    </item>
    <item>
      <title>Re: replace strings</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-replace-replace-strings/m-p/327790#M97572</link>
      <description>&lt;P&gt;I just used this and it did exactly what I wanted, put it at the end of my search and I didn't need to add extra stuff. Hence the point from me.&lt;/P&gt;</description>
      <pubDate>Tue, 09 Oct 2018 16:29:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-replace-replace-strings/m-p/327790#M97572</guid>
      <dc:creator>aebrittingham</dc:creator>
      <dc:date>2018-10-09T16:29:37Z</dc:date>
    </item>
    <item>
      <title>Re: replace strings</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-replace-replace-strings/m-p/327791#M97573</link>
      <description>&lt;P&gt;Thank you.  What if we have multiple occurrences of a string?&lt;/P&gt;

&lt;P&gt;Windows-10-Enterprise&lt;BR /&gt;
Windows-7-Enterprise&lt;BR /&gt;
WindowsServer-2008-R2-Enterprise &lt;/P&gt;

&lt;P&gt;How would we replace all the "-" characters with a space? &lt;/P&gt;</description>
      <pubDate>Thu, 11 Jul 2019 14:44:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-replace-replace-strings/m-p/327791#M97573</guid>
      <dc:creator>jaxjohnny2000</dc:creator>
      <dc:date>2019-07-11T14:44:19Z</dc:date>
    </item>
    <item>
      <title>Re: replace strings</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-replace-replace-strings/m-p/327792#M97574</link>
      <description>&lt;P&gt;You could do |rex mode=sed field=field "s/-/ /g"&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jul 2019 15:11:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-replace-replace-strings/m-p/327792#M97574</guid>
      <dc:creator>cmerriman</dc:creator>
      <dc:date>2019-07-11T15:11:58Z</dc:date>
    </item>
    <item>
      <title>Re: replace strings</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-replace-replace-strings/m-p/327793#M97575</link>
      <description>&lt;P&gt;You would probably better be served by creating a new question.  &lt;/P&gt;

&lt;P&gt;In fact, I probably shouldn't answer this here, but the answer is the easy "exactly like you'd expect" in that replace doesn't stop at the first match.  Here's a run-anywhere.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval test1 = "WindowsServer-2008-R2-Enterprise"
| eval test2 = replace(test1, "-", "")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 11 Jul 2019 15:17:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-replace-replace-strings/m-p/327793#M97575</guid>
      <dc:creator>Richfez</dc:creator>
      <dc:date>2019-07-11T15:17:20Z</dc:date>
    </item>
    <item>
      <title>Re: replace strings</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-replace-replace-strings/m-p/327794#M97576</link>
      <description>&lt;P&gt;Thanks! It really is a full regular-expression substitution (using "extended" syntax) -- with capturing groups too. You can do things like &lt;CODE&gt;replace(Field, ".* something ([A-Za-z]+) .*", "\1")&lt;/CODE&gt;. Character-classes (like &lt;CODE&gt;[[:alnum:]]&lt;/CODE&gt;) do not seem to work, but that's less important.&lt;/P&gt;</description>
      <pubDate>Fri, 13 Dec 2019 16:00:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-replace-replace-strings/m-p/327794#M97576</guid>
      <dc:creator>unitedmarsupial</dc:creator>
      <dc:date>2019-12-13T16:00:05Z</dc:date>
    </item>
    <item>
      <title>Re: replace strings</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-replace-replace-strings/m-p/655312#M226379</link>
      <description>&lt;P&gt;I tried:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;| makeresults count=10&lt;BR /&gt;| eval src=random().".wxyz.com"&lt;BR /&gt;| eval name = replace(src,".wxyz.com", ".abc.com")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To see how it worked.&lt;/P&gt;</description>
      <pubDate>Wed, 23 Aug 2023 11:48:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-replace-replace-strings/m-p/655312#M226379</guid>
      <dc:creator>neo3779_splunk</dc:creator>
      <dc:date>2023-08-23T11:48:50Z</dc:date>
    </item>
  </channel>
</rss>

