<?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: Convert #B/KB/MB/GB into bytes without a unit? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Convert-B-KB-MB-GB-into-bytes-without-a-unit/m-p/283588#M176751</link>
    <description>&lt;P&gt;Thanks...Fixed..&lt;/P&gt;</description>
    <pubDate>Tue, 13 Sep 2016 15:00:20 GMT</pubDate>
    <dc:creator>somesoni2</dc:creator>
    <dc:date>2016-09-13T15:00:20Z</dc:date>
    <item>
      <title>Convert #B/KB/MB/GB into bytes without a unit?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Convert-B-KB-MB-GB-into-bytes-without-a-unit/m-p/283585#M176748</link>
      <description>&lt;P&gt;Hey everyone. Searching around, I see tons of answers related to converting numerical bytes into KB/MB/GB/TB. However, I can't seem to find any answers going in the other direction.&lt;/P&gt;

&lt;P&gt;We have fields that can have values formatted as any of the following&lt;/P&gt;

&lt;UL&gt;
&lt;LI&gt;123B &lt;/LI&gt;
&lt;LI&gt;123KB&lt;/LI&gt;
&lt;LI&gt;123MB&lt;/LI&gt;
&lt;LI&gt;123GB&lt;/LI&gt;
&lt;LI&gt;123TB&lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;The unit used can vary by event. So the same field might be 123B in one event, then 123MB in the next event, and 123KB in the next one. I want to strip the unit off, and convert everything into bytes (I don't mind trailing zeros). How would I go about doing this?&lt;/P&gt;

&lt;P&gt;I am assuming I would need to strip the value, convert to a number, but how would I do an "if" if the unit type has already been stripped?&lt;/P&gt;</description>
      <pubDate>Tue, 13 Sep 2016 14:25:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Convert-B-KB-MB-GB-into-bytes-without-a-unit/m-p/283585#M176748</guid>
      <dc:creator>msarro</dc:creator>
      <dc:date>2016-09-13T14:25:58Z</dc:date>
    </item>
    <item>
      <title>Re: Convert #B/KB/MB/GB into bytes without a unit?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Convert-B-KB-MB-GB-into-bytes-without-a-unit/m-p/283586#M176749</link>
      <description>&lt;P&gt;Give this a try (run anywhere sample)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| gentimes start=-1 | eval WithUnit="123B 123KB 123MB 123GB 123TB" | makemv WithUnit | table WithUnit | mvexpand WithUnit
| rex field=WithUnit "^(?&amp;lt;Value&amp;gt;\d+)(?&amp;lt;Unit&amp;gt;\w*)$" | eval factor=case(Unit="B",1,Unit="KB",1024,Unit="MB",1024*1024,Unit="GB",1024*1024*1024,Unit="TB",11024*1024*1024*1024,true(),1) 
| eval InBytes=Value*factor
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 13 Sep 2016 14:36:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Convert-B-KB-MB-GB-into-bytes-without-a-unit/m-p/283586#M176749</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2016-09-13T14:36:50Z</dc:date>
    </item>
    <item>
      <title>Re: Convert #B/KB/MB/GB into bytes without a unit?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Convert-B-KB-MB-GB-into-bytes-without-a-unit/m-p/283587#M176750</link>
      <description>&lt;P&gt;Good answer. (Missing a double quote in the first &lt;CODE&gt;eval&lt;/CODE&gt;.)&lt;/P&gt;</description>
      <pubDate>Tue, 13 Sep 2016 14:57:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Convert-B-KB-MB-GB-into-bytes-without-a-unit/m-p/283587#M176750</guid>
      <dc:creator>twinspop</dc:creator>
      <dc:date>2016-09-13T14:57:13Z</dc:date>
    </item>
    <item>
      <title>Re: Convert #B/KB/MB/GB into bytes without a unit?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Convert-B-KB-MB-GB-into-bytes-without-a-unit/m-p/283588#M176751</link>
      <description>&lt;P&gt;Thanks...Fixed..&lt;/P&gt;</description>
      <pubDate>Tue, 13 Sep 2016 15:00:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Convert-B-KB-MB-GB-into-bytes-without-a-unit/m-p/283588#M176751</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2016-09-13T15:00:20Z</dc:date>
    </item>
    <item>
      <title>Re: Convert #B/KB/MB/GB into bytes without a unit?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Convert-B-KB-MB-GB-into-bytes-without-a-unit/m-p/283589#M176752</link>
      <description>&lt;P&gt;Awesome, thanks! This is actually the path I had been starting to take, but the case statement makes it a whole lot nicer than several eval if statements. I'm stealing.&lt;/P&gt;</description>
      <pubDate>Tue, 13 Sep 2016 15:01:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Convert-B-KB-MB-GB-into-bytes-without-a-unit/m-p/283589#M176752</guid>
      <dc:creator>msarro</dc:creator>
      <dc:date>2016-09-13T15:01:11Z</dc:date>
    </item>
    <item>
      <title>Re: Convert #B/KB/MB/GB into bytes without a unit?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Convert-B-KB-MB-GB-into-bytes-without-a-unit/m-p/283590#M176753</link>
      <description>&lt;P&gt;What about fields with dot?&lt;BR /&gt;
    rex field=WithUnit "^(?&lt;VALUE&gt;\d*.\d*)(?&lt;UNIT&gt;\w*)$"&lt;/UNIT&gt;&lt;/VALUE&gt;&lt;/P&gt;

&lt;P&gt;How to round them?&lt;BR /&gt;
Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 16:20:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Convert-B-KB-MB-GB-into-bytes-without-a-unit/m-p/283590#M176753</guid>
      <dc:creator>Rialf1959</dc:creator>
      <dc:date>2020-09-29T16:20:45Z</dc:date>
    </item>
  </channel>
</rss>

