<?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: Need string minus last 2 characters in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Need-string-minus-last-2-characters/m-p/91710#M23654</link>
    <description>&lt;P&gt;Hi Rachel, &lt;BR /&gt;
Using substr(myfield, 1, len(myfield)-2) is your best bet here. It turns out that rtrim will remove ALL matching characters that you supply: &lt;BR /&gt;
ex. if a=201145454545 and you do b=rtrim(a, "45") b will end being: 2011. Also, sometimes Splunk will use scientific notation after a certain number length.&lt;/P&gt;</description>
    <pubDate>Fri, 14 Oct 2011 20:48:48 GMT</pubDate>
    <dc:creator>_d_</dc:creator>
    <dc:date>2011-10-14T20:48:48Z</dc:date>
    <item>
      <title>Need string minus last 2 characters</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Need-string-minus-last-2-characters/m-p/91705#M23649</link>
      <description>&lt;P&gt;I am trying to set a field to the value of a string without the last 2 digits.  For example:&lt;/P&gt;

&lt;P&gt;Hotel=297654 from 29765423 &lt;BR /&gt;
Hotel=36345 from 3624502&lt;/P&gt;

&lt;P&gt;I tried rtrim but docs say you must know the exact string you're removing, mine are different every time.   I also tried substr but the length is not constant from 1st character and using -2 like substr(Field, -2) returns the last 2 characters...the part I want to throw away.&lt;/P&gt;

&lt;P&gt;Was trying something like rtrim(Field,substr(Field,-2) but can't get that to work.&lt;/P&gt;

&lt;P&gt;Suggestions?  - THANKS&lt;/P&gt;</description>
      <pubDate>Thu, 13 Oct 2011 17:07:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Need-string-minus-last-2-characters/m-p/91705#M23649</guid>
      <dc:creator>rachelneal</dc:creator>
      <dc:date>2011-10-13T17:07:36Z</dc:date>
    </item>
    <item>
      <title>Re: Need string minus last 2 characters</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Need-string-minus-last-2-characters/m-p/91706#M23650</link>
      <description>&lt;P&gt;Hi RachelNeal, &lt;/P&gt;

&lt;P&gt;You can extract another field and do something like this: &lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;&amp;lt;your_search_here&amp;gt; | rex field=myfield "(?&amp;lt;myfield&amp;gt;.*).{2}"&lt;/CODE&gt; &lt;/P&gt;

&lt;P&gt;This would drop off the last two chars of myfield.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Oct 2011 17:32:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Need-string-minus-last-2-characters/m-p/91706#M23650</guid>
      <dc:creator>_d_</dc:creator>
      <dc:date>2011-10-13T17:32:17Z</dc:date>
    </item>
    <item>
      <title>Re: Need string minus last 2 characters</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Need-string-minus-last-2-characters/m-p/91707#M23651</link>
      <description>&lt;P&gt;Or another way: &lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;&amp;lt;your_search_here&amp;gt; | eval myfield = substr(myfield, 1, len(myfield)-2)&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;d.&lt;/P&gt;

&lt;P&gt;-&lt;BR /&gt;
&lt;CODE&gt;please upvote if you find this answer useful&lt;/CODE&gt; &lt;/P&gt;</description>
      <pubDate>Thu, 13 Oct 2011 17:43:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Need-string-minus-last-2-characters/m-p/91707#M23651</guid>
      <dc:creator>_d_</dc:creator>
      <dc:date>2011-10-13T17:43:19Z</dc:date>
    </item>
    <item>
      <title>Re: Need string minus last 2 characters</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Need-string-minus-last-2-characters/m-p/91708#M23652</link>
      <description>&lt;P&gt;Thanks &lt;EM&gt;d&lt;/EM&gt;&lt;/P&gt;

&lt;P&gt;Out of curiosity, do you know why "eval Hotel=rtrim(Hotel,substr(Hotel,-2)) "  where Hotel was 29272905 returned 2.92729e04?&lt;/P&gt;</description>
      <pubDate>Thu, 13 Oct 2011 17:56:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Need-string-minus-last-2-characters/m-p/91708#M23652</guid>
      <dc:creator>rachelneal</dc:creator>
      <dc:date>2011-10-13T17:56:18Z</dc:date>
    </item>
    <item>
      <title>Re: Need string minus last 2 characters</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Need-string-minus-last-2-characters/m-p/91709#M23653</link>
      <description>&lt;P&gt;Yup, just tested it and you're right. It appears that this is happening with numbers only. Probably it has to do with arithmetic routines. I'll do some further investigation and perhaps touch base with engineering. Thanks.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Oct 2011 18:20:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Need-string-minus-last-2-characters/m-p/91709#M23653</guid>
      <dc:creator>_d_</dc:creator>
      <dc:date>2011-10-13T18:20:00Z</dc:date>
    </item>
    <item>
      <title>Re: Need string minus last 2 characters</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Need-string-minus-last-2-characters/m-p/91710#M23654</link>
      <description>&lt;P&gt;Hi Rachel, &lt;BR /&gt;
Using substr(myfield, 1, len(myfield)-2) is your best bet here. It turns out that rtrim will remove ALL matching characters that you supply: &lt;BR /&gt;
ex. if a=201145454545 and you do b=rtrim(a, "45") b will end being: 2011. Also, sometimes Splunk will use scientific notation after a certain number length.&lt;/P&gt;</description>
      <pubDate>Fri, 14 Oct 2011 20:48:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Need-string-minus-last-2-characters/m-p/91710#M23654</guid>
      <dc:creator>_d_</dc:creator>
      <dc:date>2011-10-14T20:48:48Z</dc:date>
    </item>
    <item>
      <title>Re: Need string minus last 2 characters</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Need-string-minus-last-2-characters/m-p/91711#M23655</link>
      <description>&lt;P&gt;Can we do it the reverse way like:&lt;/P&gt;

&lt;P&gt;string minus first 2 characters ?&lt;/P&gt;</description>
      <pubDate>Thu, 03 Dec 2015 15:31:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Need-string-minus-last-2-characters/m-p/91711#M23655</guid>
      <dc:creator>trijit</dc:creator>
      <dc:date>2015-12-03T15:31:02Z</dc:date>
    </item>
  </channel>
</rss>

