<?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: Converting alphanumeric field to numeric values (39.6K:39600) in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Converting-alphanumeric-field-to-numeric-values-39-6K-39600/m-p/294484#M88879</link>
    <description>&lt;P&gt;Sorry, just read your other comment. You'll need to know the unit if you want to do any kind of math on the converted number. So you'll have to do something similar to what niketnilay suggested above and normalize all values to bytes.&lt;/P&gt;</description>
    <pubDate>Wed, 11 Oct 2017 19:49:34 GMT</pubDate>
    <dc:creator>s2_splunk</dc:creator>
    <dc:date>2017-10-11T19:49:34Z</dc:date>
    <item>
      <title>Converting alphanumeric field to numeric values (39.6K:39600)</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Converting-alphanumeric-field-to-numeric-values-39-6K-39600/m-p/294478#M88873</link>
      <description>&lt;P&gt;I've seen numerous questions out there that touch on this topic but haven't found an answer that actually meets my specific use case.  I have data from several sources that report numeric data (such as bandwidth or other datatypes) but instead of returning the value as a number (such as 39600) it returns in this format:  39.6K.  I'm able to ingest those values but Splunk, unsurprisingly, doesn't know how to handle that - it treats it as text instead of a number.&lt;/P&gt;

&lt;P&gt;Long story short, I need a way to translate the following data points into numeric values, either at ingest time or at search time:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Congestion  39.6K  55.3K  41.2K  40.2K  39.9K  38.9K  40.9K
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;We only need to return the first value after "Congestion" - the 39.6K value.  The other values are previous poll results and we're collecting that already.  The output should end up looking like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Congestion 39600
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This specific data set should never go above "K", but I have other datasets that might go into M or G, etc., so I need something as flexible as possible.  I've tried using rex and sed but I've not had any success yet with it.  If anyone can provide any help, it'd be greatly appreciated as it will solve multiple issues for us...&lt;/P&gt;</description>
      <pubDate>Wed, 11 Oct 2017 17:17:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Converting-alphanumeric-field-to-numeric-values-39-6K-39600/m-p/294478#M88873</guid>
      <dc:creator>burras</dc:creator>
      <dc:date>2017-10-11T17:17:45Z</dc:date>
    </item>
    <item>
      <title>Re: Converting alphanumeric field to numeric values (39.6K:39600)</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Converting-alphanumeric-field-to-numeric-values-39-6K-39600/m-p/294479#M88874</link>
      <description>&lt;P&gt;If you have your Congestion value in a field called "Congestion", you can use the convert command with the &lt;A href="https://docs.splunk.com/Documentation/SplunkCloud/6.6.3/SearchReference/Convert"&gt;rmunit()&lt;/A&gt; function.&lt;BR /&gt;
If you have multiple values in a single event, the solution looks a little different.&lt;BR /&gt;
What exactly do your events look like?&lt;/P&gt;</description>
      <pubDate>Wed, 11 Oct 2017 17:25:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Converting-alphanumeric-field-to-numeric-values-39-6K-39600/m-p/294479#M88874</guid>
      <dc:creator>s2_splunk</dc:creator>
      <dc:date>2017-10-11T17:25:18Z</dc:date>
    </item>
    <item>
      <title>Re: Converting alphanumeric field to numeric values (39.6K:39600)</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Converting-alphanumeric-field-to-numeric-values-39-6K-39600/m-p/294480#M88875</link>
      <description>&lt;P&gt;We've already extracted the value out into a field that contains the alpha identifier (i.e. congestion=39.6K).  The line included above is part of a much larger event - but it will always look like the above and will only ever have a single value (no mv fields for this one).&lt;/P&gt;</description>
      <pubDate>Wed, 11 Oct 2017 18:19:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Converting-alphanumeric-field-to-numeric-values-39-6K-39600/m-p/294480#M88875</guid>
      <dc:creator>burras</dc:creator>
      <dc:date>2017-10-11T18:19:33Z</dc:date>
    </item>
    <item>
      <title>Re: Converting alphanumeric field to numeric values (39.6K:39600)</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Converting-alphanumeric-field-to-numeric-values-39-6K-39600/m-p/294481#M88876</link>
      <description>&lt;P&gt;Also of note, the values will not always have a "K" in them.  We do see events that come in like this:&lt;/P&gt;

&lt;P&gt;Congestion  0  55.3K  1836  40.2K  39.9K  38.9K  40.9K&lt;/P&gt;

&lt;P&gt;Whatever solution is devised needs to be able to account for situations where the "K" is not present - I tried the convert memk() command but it didn't handle the entries that didn't have the "K" properly (didn't convert them to K base units).&lt;/P&gt;</description>
      <pubDate>Wed, 11 Oct 2017 18:38:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Converting-alphanumeric-field-to-numeric-values-39-6K-39600/m-p/294481#M88876</guid>
      <dc:creator>burras</dc:creator>
      <dc:date>2017-10-11T18:38:23Z</dc:date>
    </item>
    <item>
      <title>Re: Converting alphanumeric field to numeric values (39.6K:39600)</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Converting-alphanumeric-field-to-numeric-values-39-6K-39600/m-p/294482#M88877</link>
      <description>&lt;P&gt;@burras, you can try the following run anywhere search. Ideally once tested with your data, you should move the same as either &lt;CODE&gt;macro&lt;/CODE&gt; or &lt;CODE&gt;Calculated Field&lt;/CODE&gt; &lt;CODE&gt;Splunk Knowledge Object&lt;/CODE&gt; for easy reuse and maintenance. Following takes care of Kilo, Mega, Giga and Tera number units.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval data="123.23K"
| eval dataInt=case( match(data,"K"),tonumber(replace(data,"([^K]+)K","\1"))*1000,
                     match(data,"M"),tonumber(replace(data,"([^M]+)M","\1"))*10000,
                     match(data,"G"),tonumber(replace(data,"([^G]+)G","\1"))*100000,
                     match(data,"T"),tonumber(replace(data,"([^T]+)T","\1"))*1000000)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;PS: Assuming you are doing simple math (i.e. 1000 multiplier) and not binary (i.e. 1024). In either case you can change as per your need/use case. First two pipes with &lt;CODE&gt;makeresults&lt;/CODE&gt; and &lt;CODE&gt;eval&lt;/CODE&gt; need to be replaced with the actual query you have. You can also test different type/precision of data by changing the value in second eval.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Oct 2017 19:04:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Converting-alphanumeric-field-to-numeric-values-39-6K-39600/m-p/294482#M88877</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-10-11T19:04:17Z</dc:date>
    </item>
    <item>
      <title>Re: Converting alphanumeric field to numeric values (39.6K:39600)</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Converting-alphanumeric-field-to-numeric-values-39-6K-39600/m-p/294483#M88878</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/3620iB8D8CB185867B1A1/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Oct 2017 19:43:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Converting-alphanumeric-field-to-numeric-values-39-6K-39600/m-p/294483#M88878</guid>
      <dc:creator>s2_splunk</dc:creator>
      <dc:date>2017-10-11T19:43:28Z</dc:date>
    </item>
    <item>
      <title>Re: Converting alphanumeric field to numeric values (39.6K:39600)</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Converting-alphanumeric-field-to-numeric-values-39-6K-39600/m-p/294484#M88879</link>
      <description>&lt;P&gt;Sorry, just read your other comment. You'll need to know the unit if you want to do any kind of math on the converted number. So you'll have to do something similar to what niketnilay suggested above and normalize all values to bytes.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Oct 2017 19:49:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Converting-alphanumeric-field-to-numeric-values-39-6K-39600/m-p/294484#M88879</guid>
      <dc:creator>s2_splunk</dc:creator>
      <dc:date>2017-10-11T19:49:34Z</dc:date>
    </item>
    <item>
      <title>Re: Converting alphanumeric field to numeric values (39.6K:39600)</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Converting-alphanumeric-field-to-numeric-values-39-6K-39600/m-p/294485#M88880</link>
      <description>&lt;P&gt;Thanks niketnilay - I ran with this and it looks like it's creating a new field called dataInt that has the new values in it.  However, I noticed that any original values that didn't contain one of the alphanumeric identifiers are completely excluded (i.e. cases where congest=0 or any other value under 10K).  Is there a way to add another statement to the case where if it doesn't match any of those you just multiply by 1?&lt;/P&gt;</description>
      <pubDate>Wed, 11 Oct 2017 20:57:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Converting-alphanumeric-field-to-numeric-values-39-6K-39600/m-p/294485#M88880</guid>
      <dc:creator>burras</dc:creator>
      <dc:date>2017-10-11T20:57:55Z</dc:date>
    </item>
    <item>
      <title>Re: Converting alphanumeric field to numeric values (39.6K:39600)</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Converting-alphanumeric-field-to-numeric-values-39-6K-39600/m-p/294486#M88881</link>
      <description>&lt;P&gt;I also noticed that while it works for values of "K", it does not appear to work for values of "M".  We just had one come in that was congestion=2.05M and the dataInt field value ended up as 20500 which would mean it's being captured by the "K" case.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Oct 2017 21:00:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Converting-alphanumeric-field-to-numeric-values-39-6K-39600/m-p/294486#M88881</guid>
      <dc:creator>burras</dc:creator>
      <dc:date>2017-10-11T21:00:44Z</dc:date>
    </item>
    <item>
      <title>Re: Converting alphanumeric field to numeric values (39.6K:39600)</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Converting-alphanumeric-field-to-numeric-values-39-6K-39600/m-p/294487#M88882</link>
      <description>&lt;P&gt;@burras, new field is for us to test and compare the outputs original field data and new field dataInt.&lt;BR /&gt;
In order to handle no Suffix in Congestion field value, you need to add a final default case using &lt;CODE&gt;true()&lt;/CODE&gt; and leave the value as it is.&lt;/P&gt;

&lt;P&gt;For your use case it would be:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;YourBaseSearch&amp;gt;
| eval Congestion=case( match(Congestion,"K"),tonumber(replace(Congestion,"([^K]+)K","\1"))*1000,
                      match(Congestion,"M"),tonumber(replace(Congestion,"([^M]+)M","\1"))*10000,
                      match(Congestion,"G"),tonumber(replace(Congestion,"([^G]+)G","\1"))*100000,
                      match(Congestion,"T"),tonumber(replace(Congestion,"([^T]+)T","\1"))*1000000,
                      true(),Congestion)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 12 Oct 2017 02:48:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Converting-alphanumeric-field-to-numeric-values-39-6K-39600/m-p/294487#M88882</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-10-12T02:48:59Z</dc:date>
    </item>
    <item>
      <title>Re: Converting alphanumeric field to numeric values (39.6K:39600)</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Converting-alphanumeric-field-to-numeric-values-39-6K-39600/m-p/294488#M88883</link>
      <description>&lt;P&gt;I tested with two values in my run anywhere example&lt;/P&gt;

&lt;P&gt;| eval data="2.05K"&lt;BR /&gt;
Which returned dataInt as 2050. And&lt;/P&gt;

&lt;P&gt;| eval data="2.05M"&lt;BR /&gt;
Which returned dataInt as 20500. These values seem to be correct as per me. Please validate again. Dont forget that you have a decimal with two digits precision.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Oct 2017 02:52:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Converting-alphanumeric-field-to-numeric-values-39-6K-39600/m-p/294488#M88883</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-10-12T02:52:14Z</dc:date>
    </item>
    <item>
      <title>Re: Converting alphanumeric field to numeric values (39.6K:39600)</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Converting-alphanumeric-field-to-numeric-values-39-6K-39600/m-p/294489#M88884</link>
      <description>&lt;P&gt;Adding the true() statement definitely seems to fix the no suffix issue.  However, I'm still seeing invalid results when the suffix if "M".  I hate not being able to upload images from work - it would make this a lot easier.&lt;/P&gt;

&lt;P&gt;Using the eval statement provided above and an event of:&lt;BR /&gt;
Network Congestion  2.11M  29.2K  27.4K  27.4K  27.4K  27.5K  37.4K&lt;/P&gt;

&lt;P&gt;I get the following results:&lt;/P&gt;

&lt;P&gt;Congestion&lt;BR /&gt;
21100&lt;BR /&gt;&lt;BR /&gt;
network_congestion&lt;BR /&gt;
2.11M&lt;/P&gt;

&lt;P&gt;With the same eval statement and a data set of:&lt;BR /&gt;
Network Congestion  21.7K  8531  8699  8755  8602  9862  0  0  0  0&lt;/P&gt;

&lt;P&gt;I get the following results:&lt;/P&gt;

&lt;P&gt;Congestion&lt;BR /&gt;
21700&lt;BR /&gt;&lt;BR /&gt;
network_congestion&lt;BR /&gt;
21.7K&lt;/P&gt;</description>
      <pubDate>Mon, 16 Oct 2017 15:18:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Converting-alphanumeric-field-to-numeric-values-39-6K-39600/m-p/294489#M88884</guid>
      <dc:creator>burras</dc:creator>
      <dc:date>2017-10-16T15:18:08Z</dc:date>
    </item>
    <item>
      <title>Re: Converting alphanumeric field to numeric values (39.6K:39600)</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Converting-alphanumeric-field-to-numeric-values-39-6K-39600/m-p/294490#M88885</link>
      <description>&lt;P&gt;@burras, 2.11M is correctly evaluating to 21100. I hope you are treating M as &lt;CODE&gt;Mega&lt;/CODE&gt; and not &lt;CODE&gt;Million&lt;/CODE&gt;. Just to ensure that I am not misinterpreting your expectation, what it the result you are expecting for 2.11M?&lt;/P&gt;</description>
      <pubDate>Mon, 16 Oct 2017 19:13:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Converting-alphanumeric-field-to-numeric-values-39-6K-39600/m-p/294490#M88885</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-10-16T19:13:02Z</dc:date>
    </item>
    <item>
      <title>Re: Converting alphanumeric field to numeric values (39.6K:39600)</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Converting-alphanumeric-field-to-numeric-values-39-6K-39600/m-p/294491#M88886</link>
      <description>&lt;P&gt;In this particular case K actually does equate to thousands while M equates to millions - not necessary kilo and mega.  21.7K should value out to 21700 while 2.11M should value out to 2110000.  We don't see any values higher than an M ever.  I adjusted the M to multiply by 1000000 and that fixed the problem.  Thanks for all your help with this and I'll definitely be able to apply to my others use cases!&lt;/P&gt;</description>
      <pubDate>Mon, 16 Oct 2017 20:52:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Converting-alphanumeric-field-to-numeric-values-39-6K-39600/m-p/294491#M88886</guid>
      <dc:creator>burras</dc:creator>
      <dc:date>2017-10-16T20:52:58Z</dc:date>
    </item>
  </channel>
</rss>

