<?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: Not able to convert field from string to number in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Not-able-to-convert-field-from-string-to-number/m-p/500023#M139276</link>
    <description>&lt;P&gt;@woodcock &lt;BR /&gt;
I already tried using trim once but it didn't worked.&lt;BR /&gt;
Anyways thanks for the help.&lt;/P&gt;</description>
    <pubDate>Fri, 27 Mar 2020 06:55:16 GMT</pubDate>
    <dc:creator>nilbak1</dc:creator>
    <dc:date>2020-03-27T06:55:16Z</dc:date>
    <item>
      <title>Not able to convert field from string to number</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Not-able-to-convert-field-from-string-to-number/m-p/500019#M139272</link>
      <description>&lt;P&gt;The below is my query to extact fields from screenshot attached.&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;index=***** host=***** source=******  &lt;BR /&gt;
| rex field=_raw max_match=0 "(?[a-z]+),(?\w+\-?\d?.*)\,(?\d?.*)"&lt;/CODE&gt;&lt;/P&gt;

&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/8574i8C4EC2D5566A2B3F/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;Now I want to convert Size field from string to numeric as have to perform various statistical operations. &lt;BR /&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/8575i4D96CD9591339FDF/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;I used tonumber, convert, fieldformat but none worked.&lt;/P&gt;

&lt;P&gt;This is my final query&lt;BR /&gt;
&lt;CODE&gt;&lt;BR /&gt;
 index=**** host=***** source=******** &lt;BR /&gt;
 | rex field=_raw max_match=0 "(?[a-z]+),(?\w+\-?\d?.*)\,(?\d?.*)"&lt;BR /&gt;
| table Brand,Size,Files&lt;BR /&gt;
 | eval _counter = mvrange(0,mvcount(Brand))&lt;BR /&gt;
 | stats list(*) as * by _counter&lt;BR /&gt;
 | foreach * [ eval &amp;lt;&amp;gt; = mvindex('&amp;lt;&amp;gt;' , _counter)]&lt;BR /&gt;
 | xyseries Brand Files Size&lt;BR /&gt;
 | transpose 0 header_field=Brand column_name=Files  &lt;BR /&gt;
 | foreach * [ eval &amp;lt;&amp;gt; = if(isnull(&amp;lt;&amp;gt;) OR len(&amp;lt;&amp;gt;)==0, "0", &amp;lt;&amp;gt;) ]&lt;BR /&gt;
&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;I have to convert Size values from kb into mb for this I need to change them from string to number.&lt;/P&gt;</description>
      <pubDate>Wed, 25 Mar 2020 10:02:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Not-able-to-convert-field-from-string-to-number/m-p/500019#M139272</guid>
      <dc:creator>nilbak1</dc:creator>
      <dc:date>2020-03-25T10:02:20Z</dc:date>
    </item>
    <item>
      <title>Re: Not able to convert field from string to number</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Not-able-to-convert-field-from-string-to-number/m-p/500020#M139273</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;Please try below query&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;yourBaseQuery&amp;gt;
| rex field=_raw max_match=0 "(?&amp;lt;linedata&amp;gt;[^\r\n]+)"
| mvexpand linedata
| rex field=linedata max_match=0 "(?&amp;lt;Brand&amp;gt;[a-z]+),(?&amp;lt;Files&amp;gt;\w+\-?\d?.*)\,(?&amp;lt;Size&amp;gt;\d?.*)"
| fields Brand, Files, Size
| eval Size=Size/1024, {Brand}=Size
| stats values(*) as * by Files
| foreach * [ eval &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt; = if(isnull(&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;), 0, &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;) ]
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 26 Mar 2020 13:00:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Not-able-to-convert-field-from-string-to-number/m-p/500020#M139273</guid>
      <dc:creator>harsmarvania57</dc:creator>
      <dc:date>2020-03-26T13:00:38Z</dc:date>
    </item>
    <item>
      <title>Re: Not able to convert field from string to number</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Not-able-to-convert-field-from-string-to-number/m-p/500021#M139274</link>
      <description>&lt;P&gt;It probably has whitespace around it so try adding &lt;CODE&gt;trim()&lt;/CODE&gt; like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval Size="  3 " 
| eval Size = tonumber(trim(Size)) 
| eval type=typeof(Size)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 26 Mar 2020 13:49:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Not-able-to-convert-field-from-string-to-number/m-p/500021#M139274</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2020-03-26T13:49:54Z</dc:date>
    </item>
    <item>
      <title>Re: Not able to convert field from string to number</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Not-able-to-convert-field-from-string-to-number/m-p/500022#M139275</link>
      <description>&lt;P&gt;Thanks @harsmarvania57 .&lt;BR /&gt;
It worked perfectly.&lt;/P&gt;</description>
      <pubDate>Fri, 27 Mar 2020 06:53:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Not-able-to-convert-field-from-string-to-number/m-p/500022#M139275</guid>
      <dc:creator>nilbak1</dc:creator>
      <dc:date>2020-03-27T06:53:42Z</dc:date>
    </item>
    <item>
      <title>Re: Not able to convert field from string to number</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Not-able-to-convert-field-from-string-to-number/m-p/500023#M139276</link>
      <description>&lt;P&gt;@woodcock &lt;BR /&gt;
I already tried using trim once but it didn't worked.&lt;BR /&gt;
Anyways thanks for the help.&lt;/P&gt;</description>
      <pubDate>Fri, 27 Mar 2020 06:55:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Not-able-to-convert-field-from-string-to-number/m-p/500023#M139276</guid>
      <dc:creator>nilbak1</dc:creator>
      <dc:date>2020-03-27T06:55:16Z</dc:date>
    </item>
  </channel>
</rss>

