<?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: Why is trim not working when the field has &amp;quot;#&amp;quot;? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Why-is-trim-not-working-when-the-field-has-quot-quot/m-p/251742#M176104</link>
    <description>&lt;P&gt;Trim function is ideally meant to remove spaces, that is when you just provide the input string to the trim function. In Splunk trim, ltrim and rtrim can accept two input parameters i.e. input string and trim character/s. However, you should understand that trim removes the fields only from beginning and/or the end of the input string and &lt;STRONG&gt;not from middle&lt;/STRONG&gt;.&lt;/P&gt;

&lt;P&gt;This behavior of Trim is not specific to Splunk, it is expected across all languages/technologies.&lt;/P&gt;

&lt;P&gt;The output of the following trim &lt;STRONG&gt;command&lt;/STRONG&gt; will be &lt;STRONG&gt;a##bc&lt;/STRONG&gt;.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;eval x=trim("####a##bc###", "#") | table x
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Refer to trim eval function on Splunk documentation: &lt;A href="https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/CommonEvalFunctions"&gt;https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/CommonEvalFunctions&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 30 Nov 2016 17:42:58 GMT</pubDate>
    <dc:creator>niketn</dc:creator>
    <dc:date>2016-11-30T17:42:58Z</dc:date>
    <item>
      <title>Why is trim not working when the field has "#"?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-is-trim-not-working-when-the-field-has-quot-quot/m-p/251738#M176100</link>
      <description>&lt;P&gt;I've tried to use the &lt;CODE&gt;trim&lt;/CODE&gt;, &lt;CODE&gt;ltrim&lt;/CODE&gt;, and &lt;CODE&gt;rtrim&lt;/CODE&gt; command on a particular field that contains a "#" field.&lt;/P&gt;

&lt;P&gt;I'm not a traditional programmer but it appears the command just fails silently. I've tried it at search-time (e.g. eval test=trim("test#123","#") and i've tried it as a calculated field. Trim("test # 123") also fails to remove the spaces. &lt;/P&gt;

&lt;P&gt;Is this a possible bug or am I not using the command correctly? I've read the Eval Functions page and it doesn't capture this case. &lt;/P&gt;

&lt;P&gt;I'm on 6.4.3 btw.&lt;/P&gt;

&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Nov 2016 16:56:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-is-trim-not-working-when-the-field-has-quot-quot/m-p/251738#M176100</guid>
      <dc:creator>_jgpm_</dc:creator>
      <dc:date>2016-11-30T16:56:39Z</dc:date>
    </item>
    <item>
      <title>Re: Why is trim not working when the field has "#"?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-is-trim-not-working-when-the-field-has-quot-quot/m-p/251739#M176101</link>
      <description>&lt;P&gt;I think the issue here is the interpretation of the way trim works. Trim will remove Leading or Trailing characters (or spaces).&lt;/P&gt;

&lt;P&gt;For example&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval test=trim("##test123","#")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Will remove the leading "#"s&lt;/P&gt;

&lt;P&gt;If you are just trying to remove the "#" try using replace&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|eval test=replace("test#123","#","")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Sed is also a valid case for this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|stats count|fields - count|eval test="test# 123" |rex mode=sed field=test "s/#|\s//g"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;For example in the above SPL we remove the "#" and the space.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Nov 2016 17:24:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-is-trim-not-working-when-the-field-has-quot-quot/m-p/251739#M176101</guid>
      <dc:creator>Flynt</dc:creator>
      <dc:date>2016-11-30T17:24:45Z</dc:date>
    </item>
    <item>
      <title>Re: Why is trim not working when the field has "#"?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-is-trim-not-working-when-the-field-has-quot-quot/m-p/251740#M176102</link>
      <description>&lt;P&gt;That's what I ended up doing. I guess this was more due to that I'm not a programmer than the documentation lacking or a bug in Splunk. Thanks.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Nov 2016 17:41:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-is-trim-not-working-when-the-field-has-quot-quot/m-p/251740#M176102</guid>
      <dc:creator>_jgpm_</dc:creator>
      <dc:date>2016-11-30T17:41:32Z</dc:date>
    </item>
    <item>
      <title>Re: Why is trim not working when the field has "#"?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-is-trim-not-working-when-the-field-has-quot-quot/m-p/251741#M176103</link>
      <description>&lt;P&gt;yas, trim, as the name suggests, trims only on two edges - &lt;BR /&gt;
the Leading (or left trim - properly named as "ltrim") &lt;BR /&gt;
or &lt;BR /&gt;
the trailing (or right(properly named as "rtrim")) characters. &lt;/P&gt;

&lt;P&gt;to do something like, test=trim("test#123","#"), we have to use replace or sed only&lt;/P&gt;</description>
      <pubDate>Wed, 30 Nov 2016 17:42:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-is-trim-not-working-when-the-field-has-quot-quot/m-p/251741#M176103</guid>
      <dc:creator>inventsekar</dc:creator>
      <dc:date>2016-11-30T17:42:10Z</dc:date>
    </item>
    <item>
      <title>Re: Why is trim not working when the field has "#"?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-is-trim-not-working-when-the-field-has-quot-quot/m-p/251742#M176104</link>
      <description>&lt;P&gt;Trim function is ideally meant to remove spaces, that is when you just provide the input string to the trim function. In Splunk trim, ltrim and rtrim can accept two input parameters i.e. input string and trim character/s. However, you should understand that trim removes the fields only from beginning and/or the end of the input string and &lt;STRONG&gt;not from middle&lt;/STRONG&gt;.&lt;/P&gt;

&lt;P&gt;This behavior of Trim is not specific to Splunk, it is expected across all languages/technologies.&lt;/P&gt;

&lt;P&gt;The output of the following trim &lt;STRONG&gt;command&lt;/STRONG&gt; will be &lt;STRONG&gt;a##bc&lt;/STRONG&gt;.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;eval x=trim("####a##bc###", "#") | table x
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Refer to trim eval function on Splunk documentation: &lt;A href="https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/CommonEvalFunctions"&gt;https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/CommonEvalFunctions&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Nov 2016 17:42:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-is-trim-not-working-when-the-field-has-quot-quot/m-p/251742#M176104</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2016-11-30T17:42:58Z</dc:date>
    </item>
  </channel>
</rss>

