<?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 substr can't get the correct value? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/substr-can-t-get-the-correct-value/m-p/89670#M22992</link>
    <description>&lt;P&gt;Hi,all&lt;/P&gt;

&lt;P&gt;I want to use "substr" to get what I want.&lt;/P&gt;

&lt;P&gt;A=1420014&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... |eval A=if(substr(A, 1,2)="14",replace(A, "14", "0"),A) |table A
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;A will become "02000".&lt;/P&gt;

&lt;P&gt;But it should be "020014".&lt;/P&gt;

&lt;P&gt;Could anyone tell me what's worng?
Can't I use substr by this way?&lt;/P&gt;

&lt;P&gt;Thanks a lot. &lt;span class="lia-unicode-emoji" title=":grinning_face_with_big_eyes:"&gt;😃&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 16 Nov 2010 11:41:43 GMT</pubDate>
    <dc:creator>flora123</dc:creator>
    <dc:date>2010-11-16T11:41:43Z</dc:date>
    <item>
      <title>substr can't get the correct value?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/substr-can-t-get-the-correct-value/m-p/89670#M22992</link>
      <description>&lt;P&gt;Hi,all&lt;/P&gt;

&lt;P&gt;I want to use "substr" to get what I want.&lt;/P&gt;

&lt;P&gt;A=1420014&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... |eval A=if(substr(A, 1,2)="14",replace(A, "14", "0"),A) |table A
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;A will become "02000".&lt;/P&gt;

&lt;P&gt;But it should be "020014".&lt;/P&gt;

&lt;P&gt;Could anyone tell me what's worng?
Can't I use substr by this way?&lt;/P&gt;

&lt;P&gt;Thanks a lot. &lt;span class="lia-unicode-emoji" title=":grinning_face_with_big_eyes:"&gt;😃&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Nov 2010 11:41:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/substr-can-t-get-the-correct-value/m-p/89670#M22992</guid>
      <dc:creator>flora123</dc:creator>
      <dc:date>2010-11-16T11:41:43Z</dc:date>
    </item>
    <item>
      <title>Re: substr can't get the correct value?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/substr-can-t-get-the-correct-value/m-p/89671#M22993</link>
      <description>&lt;P&gt;The replace operator will replace every occurence of a value in a string.  From &lt;A href="http://www.splunk.com/base/Documentation/latest/SearchReference/CommonEvalFunctions" rel="nofollow"&gt;http://www.splunk.com/base/Documentation/latest/SearchReference/CommonEvalFunctions&lt;/A&gt; :&lt;/P&gt;

&lt;BLOCKQUOTE&gt;
  &lt;P&gt;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;/BLOCKQUOTE&gt;

&lt;P&gt;Given your example above, there are a couple of ways to attack it.  If you're always wanting to replace the "14" (or whatever) at the beginning, you should be able to take advantage of the fact that replace uses regexes, and do something like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | eval A=if(substr(A,1,2)="14",replace(A,"^14","0"),A) | table A
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Or you can accomplish the same thing with string concatenation, similar to:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | eval A=if(substr(A,1,2)="14", "0".substr(A,3), A) | table A
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 16 Nov 2010 12:16:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/substr-can-t-get-the-correct-value/m-p/89671#M22993</guid>
      <dc:creator>dwaddle</dc:creator>
      <dc:date>2010-11-16T12:16:54Z</dc:date>
    </item>
    <item>
      <title>Re: substr can't get the correct value?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/substr-can-t-get-the-correct-value/m-p/89672#M22994</link>
      <description>&lt;P&gt;Wonderful!Thanks a lot.&lt;/P&gt;</description>
      <pubDate>Tue, 16 Nov 2010 12:33:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/substr-can-t-get-the-correct-value/m-p/89672#M22994</guid>
      <dc:creator>flora123</dc:creator>
      <dc:date>2010-11-16T12:33:03Z</dc:date>
    </item>
  </channel>
</rss>

