<?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: How to use the eval replace function in dashboard xml in Dashboards &amp; Visualizations</title>
    <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-use-the-eval-replace-function-in-dashboard-xml/m-p/299124#M19005</link>
    <description>&lt;P&gt;Could you use split?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;*|eval inputfield="a b c d"|eval temp=split(inputfield," ") | eval outputfield=mvindex(temp,0).",".mvindex(temp,1).",".mvindex(temp,2).",".mvindex(temp,3)|table inputfield outputfield
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;this produces&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;inputfield | outputfield
a b c d | a,b,c,d
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 14 Feb 2017 22:48:07 GMT</pubDate>
    <dc:creator>nickhills</dc:creator>
    <dc:date>2017-02-14T22:48:07Z</dc:date>
    <item>
      <title>How to use the eval replace function in dashboard xml</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-use-the-eval-replace-function-in-dashboard-xml/m-p/299123#M19004</link>
      <description>&lt;P&gt;Note this question relates to the replace eval function, not the replace search command.  I've been referring to the documentation in &lt;A href="https://docs.splunk.com/Documentation/Splunk/6.5.2/SearchReference/CommonEvalFunctions"&gt;https://docs.splunk.com/Documentation/Splunk/6.5.2/SearchReference/CommonEvalFunctions&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;My requirement is to take a list of space-delimited values in an input field and turn it into a comma-separated list for passing to the search  For example, a b c d in the input should be transformed to ('a','b','c','d').  Here's my input definition from the dashboard:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; &amp;lt;input type="text" searchWhenChanged="false" token="order_number"&amp;gt;
  &amp;lt;label&amp;gt;Order Number&amp;lt;/label&amp;gt;
  &amp;lt;default&amp;gt;&amp;lt;/default&amp;gt;
  &amp;lt;change&amp;gt;
    &amp;lt;eval token="order_number_q"&amp;gt;if($value$=="","","('"+replace(ltrim(rtrim($value$))," +","','")+"') ")&amp;lt;/eval&amp;gt;
  &amp;lt;/change&amp;gt;
&amp;lt;/input&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The issue is that only the first instance of the space is replaced - so with my example above I'm ending up with ('a','b c d')&lt;/P&gt;

&lt;P&gt;Documentation on the replace evaluation function is light, and I haven't found anyone else in Splunk Answers experiencing this behavior.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Feb 2017 22:34:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-use-the-eval-replace-function-in-dashboard-xml/m-p/299123#M19004</guid>
      <dc:creator>bobbycrispbox</dc:creator>
      <dc:date>2017-02-14T22:34:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to use the eval replace function in dashboard xml</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-use-the-eval-replace-function-in-dashboard-xml/m-p/299124#M19005</link>
      <description>&lt;P&gt;Could you use split?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;*|eval inputfield="a b c d"|eval temp=split(inputfield," ") | eval outputfield=mvindex(temp,0).",".mvindex(temp,1).",".mvindex(temp,2).",".mvindex(temp,3)|table inputfield outputfield
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;this produces&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;inputfield | outputfield
a b c d | a,b,c,d
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 14 Feb 2017 22:48:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-use-the-eval-replace-function-in-dashboard-xml/m-p/299124#M19005</guid>
      <dc:creator>nickhills</dc:creator>
      <dc:date>2017-02-14T22:48:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to use the eval replace function in dashboard xml</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-use-the-eval-replace-function-in-dashboard-xml/m-p/299125#M19006</link>
      <description>&lt;P&gt;I should point out that a b c d could be a b c d e f -- I need to keep this solution general to accept any number of space-separated inputs.  Your solution looks like it would need to fix the number of outputs.&lt;/P&gt;

&lt;P&gt;I note that replace does work as I would have expected in the context of a search, like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;*|eval inputfield="a b c d"|eval outputfield="('"+replace(inputfield," ","'','")+"')" |table inputfield outputfield
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;but it does not in the context of a dashboard input.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Feb 2017 23:04:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-use-the-eval-replace-function-in-dashboard-xml/m-p/299125#M19006</guid>
      <dc:creator>bobbycrispbox</dc:creator>
      <dc:date>2017-02-14T23:04:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to use the eval replace function in dashboard xml</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-use-the-eval-replace-function-in-dashboard-xml/m-p/299126#M19007</link>
      <description>&lt;P&gt;Have you tried replacing the space character with \s?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;     &amp;lt;eval token="order_number_q"&amp;gt;if($value$=="","","('"+replace(ltrim(rtrim($value$)),"\s+","','")+"') ")&amp;lt;/eval&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;It's possible the space is getting borked somehow via XML.&lt;/P&gt;</description>
      <pubDate>Fri, 30 Mar 2018 03:22:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-use-the-eval-replace-function-in-dashboard-xml/m-p/299126#M19007</guid>
      <dc:creator>Kenshiro70</dc:creator>
      <dc:date>2018-03-30T03:22:32Z</dc:date>
    </item>
  </channel>
</rss>

