<?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: conditional converion in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/conditional-converion/m-p/86884#M22184</link>
    <description>&lt;P&gt;Oh right.  No problem.  it's easy. I'll update my answer.&lt;/P&gt;</description>
    <pubDate>Mon, 08 Apr 2013 03:19:14 GMT</pubDate>
    <dc:creator>sideview</dc:creator>
    <dc:date>2013-04-08T03:19:14Z</dc:date>
    <item>
      <title>conditional converion</title>
      <link>https://community.splunk.com/t5/Splunk-Search/conditional-converion/m-p/86881#M22181</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;

&lt;P&gt;I have a field called "diskin" which can have two values in two measurements &lt;/P&gt;

&lt;P&gt;1) K for kilobytes&lt;BR /&gt;&lt;BR /&gt;
2) M for megabytes&lt;/P&gt;

&lt;P&gt;eg:  diskin=9.9M, diskin=948K etc&lt;/P&gt;

&lt;P&gt;How do i auto covert them to a single measurement say in bytes  during search time ?&lt;/P&gt;

&lt;P&gt;Thanks&lt;/P&gt;

&lt;P&gt;Regards&lt;/P&gt;

&lt;P&gt;KK&lt;/P&gt;</description>
      <pubDate>Mon, 08 Apr 2013 01:56:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/conditional-converion/m-p/86881#M22181</guid>
      <dc:creator>KarunK</dc:creator>
      <dc:date>2013-04-08T01:56:15Z</dc:date>
    </item>
    <item>
      <title>Re: conditional converion</title>
      <link>https://community.splunk.com/t5/Splunk-Search/conditional-converion/m-p/86882#M22182</link>
      <description>&lt;P&gt;You can use the if() function in eval, along with the substr() function to check the last character of the diskin field: &lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;... | eval bytes=if(substr(diskin,-1)=="M",diskin/(1024*1024),diskin/1024)&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;If you have more than two cases, it's cleaner to use the case() function. Even with only 2 cases, it's a bit of a tossup.   Here's the same functionality but with the case() function. &lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;...| eval bytes=case(substr(diskin,-1)=="M",diskin/(1024*1024), substr(diskin,-1)=="K", ,diskin/1024)&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;&lt;A href="http://docs.splunk.com/Documentation/Splunk/5.0.2/SearchReference/CommonEvalFunctions"&gt;http://docs.splunk.com/Documentation/Splunk/5.0.2/SearchReference/CommonEvalFunctions&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;UPDATE: &lt;/P&gt;

&lt;P&gt;Sorry I forgot that those suffixes will prevent the field from being treated as a numeric field.  Splunk will sometimes forgive a certain amount of strangeness and treat values as numeric anyway, but indeed it does not in this case and the division above fails.  &lt;/P&gt;

&lt;P&gt;But you can easily make yourself a numeric field by clipping off the suffix, and the overall search language then looks like: &lt;/P&gt;

&lt;P&gt;with the eval command's if() function: &lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;... | eval suffix=substr(diskin,-1) | eval value=substr(diskin,0,length(diskin)-1) | eval bytes=if(suffix=="M",value/(1024*1024),value/1024)&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;with the case() function instead: &lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;... | eval suffix=substr(diskin,-1) | eval value=substr(diskin,0,length(diskin)-1) | eval bytes=case(suffix=="M",value/(1024*1024),suffix=="K",value/1024)&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Apr 2013 02:02:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/conditional-converion/m-p/86882#M22182</guid>
      <dc:creator>sideview</dc:creator>
      <dc:date>2013-04-08T02:02:37Z</dc:date>
    </item>
    <item>
      <title>Re: conditional converion</title>
      <link>https://community.splunk.com/t5/Splunk-Search/conditional-converion/m-p/86883#M22183</link>
      <description>&lt;P&gt;Ies i have tried this but "diskin/1024" wont work since, diskin is alphanumeric (eg:diskin=9.9M/1024)&lt;/P&gt;</description>
      <pubDate>Mon, 08 Apr 2013 02:13:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/conditional-converion/m-p/86883#M22183</guid>
      <dc:creator>KarunK</dc:creator>
      <dc:date>2013-04-08T02:13:00Z</dc:date>
    </item>
    <item>
      <title>Re: conditional converion</title>
      <link>https://community.splunk.com/t5/Splunk-Search/conditional-converion/m-p/86884#M22184</link>
      <description>&lt;P&gt;Oh right.  No problem.  it's easy. I'll update my answer.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Apr 2013 03:19:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/conditional-converion/m-p/86884#M22184</guid>
      <dc:creator>sideview</dc:creator>
      <dc:date>2013-04-08T03:19:14Z</dc:date>
    </item>
    <item>
      <title>Re: conditional converion</title>
      <link>https://community.splunk.com/t5/Splunk-Search/conditional-converion/m-p/86885#M22185</link>
      <description>&lt;P&gt;Thanks it worked....&lt;/P&gt;

&lt;P&gt;Cheers&lt;/P&gt;

&lt;P&gt;KK&lt;/P&gt;</description>
      <pubDate>Mon, 08 Apr 2013 04:46:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/conditional-converion/m-p/86885#M22185</guid>
      <dc:creator>KarunK</dc:creator>
      <dc:date>2013-04-08T04:46:16Z</dc:date>
    </item>
  </channel>
</rss>

