<?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: Why am I unable to convert a string to numeric? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Why-am-I-unable-to-convert-a-string-to-numeric/m-p/354264#M104861</link>
    <description>&lt;P&gt;Can you give some sample values for the &lt;CODE&gt;total_run_time&lt;/CODE&gt; field that you're trying to convert?&lt;/P&gt;</description>
    <pubDate>Fri, 20 Apr 2018 17:49:22 GMT</pubDate>
    <dc:creator>elliotproebstel</dc:creator>
    <dc:date>2018-04-20T17:49:22Z</dc:date>
    <item>
      <title>Why am I unable to convert a string to numeric?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-am-I-unable-to-convert-a-string-to-numeric/m-p/354262#M104859</link>
      <description>&lt;P&gt;I am trying to convert a string to numeric but it is not getting converted.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="dnr_ecc" jobname="*IC*HV_TREX" | eval runtime = tonumber(total_run_time) |
table jobname total_run_time runtime
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Runtime field is displaying as blank. I need this to covert to numeric so I can use the sum functional to sum the runtime.&lt;/P&gt;

&lt;P&gt;Any help is much appreciated.&lt;/P&gt;</description>
      <pubDate>Fri, 20 Apr 2018 17:21:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-am-I-unable-to-convert-a-string-to-numeric/m-p/354262#M104859</guid>
      <dc:creator>sjafferali</dc:creator>
      <dc:date>2018-04-20T17:21:24Z</dc:date>
    </item>
    <item>
      <title>Re: Why am I unable to convert a string to numeric?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-am-I-unable-to-convert-a-string-to-numeric/m-p/354263#M104860</link>
      <description>&lt;P&gt;I tried the below after using the convert command, but the result comes as "False"&lt;/P&gt;

&lt;P&gt;index="dnr_ecc" jobname="*IC*HV_TREX" | convert num(total_run_time) as runtime |&lt;BR /&gt;
eval result=if(isNum(runtime),"True","False") |&lt;BR /&gt;
table result&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 19:10:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-am-I-unable-to-convert-a-string-to-numeric/m-p/354263#M104860</guid>
      <dc:creator>sjafferali</dc:creator>
      <dc:date>2020-09-29T19:10:52Z</dc:date>
    </item>
    <item>
      <title>Re: Why am I unable to convert a string to numeric?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-am-I-unable-to-convert-a-string-to-numeric/m-p/354264#M104861</link>
      <description>&lt;P&gt;Can you give some sample values for the &lt;CODE&gt;total_run_time&lt;/CODE&gt; field that you're trying to convert?&lt;/P&gt;</description>
      <pubDate>Fri, 20 Apr 2018 17:49:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-am-I-unable-to-convert-a-string-to-numeric/m-p/354264#M104861</guid>
      <dc:creator>elliotproebstel</dc:creator>
      <dc:date>2018-04-20T17:49:22Z</dc:date>
    </item>
    <item>
      <title>Re: Why am I unable to convert a string to numeric?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-am-I-unable-to-convert-a-string-to-numeric/m-p/354265#M104862</link>
      <description>&lt;P&gt;Try this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="dnr_ecc" jobname="*IC*HV_TREX" |convert dur2sec(total_run_time) as runtime |
 table jobname total_run_time runtime
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 20 Apr 2018 18:18:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-am-I-unable-to-convert-a-string-to-numeric/m-p/354265#M104862</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2018-04-20T18:18:03Z</dc:date>
    </item>
    <item>
      <title>Re: Why am I unable to convert a string to numeric?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-am-I-unable-to-convert-a-string-to-numeric/m-p/354266#M104863</link>
      <description>&lt;P&gt;total run time looks like in numberic format. it is in seconds like if 3400 seconds is the runtime, total_run_time will have "3400", if 15000 then "15000"&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 19:11:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-am-I-unable-to-convert-a-string-to-numeric/m-p/354266#M104863</guid>
      <dc:creator>sjafferali</dc:creator>
      <dc:date>2020-09-29T19:11:00Z</dc:date>
    </item>
    <item>
      <title>Re: Why am I unable to convert a string to numeric?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-am-I-unable-to-convert-a-string-to-numeric/m-p/354267#M104864</link>
      <description>&lt;P&gt;during dur2sec is still not working.&lt;/P&gt;</description>
      <pubDate>Fri, 20 Apr 2018 18:47:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-am-I-unable-to-convert-a-string-to-numeric/m-p/354267#M104864</guid>
      <dc:creator>sjafferali</dc:creator>
      <dc:date>2018-04-20T18:47:48Z</dc:date>
    </item>
    <item>
      <title>Re: Why am I unable to convert a string to numeric?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-am-I-unable-to-convert-a-string-to-numeric/m-p/354268#M104865</link>
      <description>&lt;P&gt;Does the field contain something besides just a number? What do you get from this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="dnr_ecc" jobname="*IC*HV_TREX" total_run_time=*
| head 5
| stats values(total_run_time)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Can you copy and paste the results here?&lt;/P&gt;</description>
      <pubDate>Fri, 20 Apr 2018 19:20:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-am-I-unable-to-convert-a-string-to-numeric/m-p/354268#M104865</guid>
      <dc:creator>elliotproebstel</dc:creator>
      <dc:date>2018-04-20T19:20:15Z</dc:date>
    </item>
    <item>
      <title>Re: Why am I unable to convert a string to numeric?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-am-I-unable-to-convert-a-string-to-numeric/m-p/354269#M104866</link>
      <description>&lt;P&gt;Does total_run_time has value &lt;CODE&gt;3400 seconds&lt;/CODE&gt; (number with string unit in it) OR just &lt;CODE&gt;3400&lt;/CODE&gt;? &lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 19:09:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-am-I-unable-to-convert-a-string-to-numeric/m-p/354269#M104866</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2020-09-29T19:09:40Z</dc:date>
    </item>
    <item>
      <title>Re: Why am I unable to convert a string to numeric?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-am-I-unable-to-convert-a-string-to-numeric/m-p/354270#M104867</link>
      <description>&lt;P&gt;If &lt;CODE&gt;total_run_time&lt;/CODE&gt; looks like "3400 seconds", then you could use a rex command to extract the first series of numbers it encounters in the field:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rex mode=sed field=total_run_time "s/^(\d+)([^\d].*)/\1/"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;So that would turn &lt;CODE&gt;3400 seconds&lt;/CODE&gt; into &lt;CODE&gt;3400&lt;/CODE&gt;.&lt;/P&gt;</description>
      <pubDate>Fri, 20 Apr 2018 20:07:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-am-I-unable-to-convert-a-string-to-numeric/m-p/354270#M104867</guid>
      <dc:creator>elliotproebstel</dc:creator>
      <dc:date>2018-04-20T20:07:49Z</dc:date>
    </item>
    <item>
      <title>Re: Why am I unable to convert a string to numeric?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-am-I-unable-to-convert-a-string-to-numeric/m-p/354271#M104868</link>
      <description>&lt;P&gt;I ran the query you gave &lt;BR /&gt;
index="dnr_ecc" jobname="&lt;EM&gt;IC*HV_TREX" total_run_time=&lt;/EM&gt; | head 5 | stats values(total_run_time)&lt;BR /&gt;
Result is as below. There is no text in the field.&lt;/P&gt;

&lt;P&gt;values(total_run_time)&lt;BR /&gt;
1540&lt;BR /&gt;
1751&lt;BR /&gt;
1780&lt;BR /&gt;
1832&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 19:11:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-am-I-unable-to-convert-a-string-to-numeric/m-p/354271#M104868</guid>
      <dc:creator>sjafferali</dc:creator>
      <dc:date>2020-09-29T19:11:03Z</dc:date>
    </item>
    <item>
      <title>Re: Why am I unable to convert a string to numeric?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-am-I-unable-to-convert-a-string-to-numeric/m-p/354272#M104869</link>
      <description>&lt;P&gt;I ran the query you gave &lt;BR /&gt;
index="dnr_ecc" jobname="IC*HV_TREX" total_run_time= | head 5 | stats values(total_run_time)&lt;BR /&gt;
Result is as below. There is no text in the field.&lt;/P&gt;

&lt;P&gt;values(total_run_time)&lt;BR /&gt;
1540&lt;BR /&gt;
1751&lt;BR /&gt;
1780&lt;BR /&gt;
1832&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 19:11:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-am-I-unable-to-convert-a-string-to-numeric/m-p/354272#M104869</guid>
      <dc:creator>sjafferali</dc:creator>
      <dc:date>2020-09-29T19:11:06Z</dc:date>
    </item>
    <item>
      <title>Re: Why am I unable to convert a string to numeric?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-am-I-unable-to-convert-a-string-to-numeric/m-p/354273#M104870</link>
      <description>&lt;P&gt;It has just 3400&lt;/P&gt;</description>
      <pubDate>Fri, 20 Apr 2018 21:13:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-am-I-unable-to-convert-a-string-to-numeric/m-p/354273#M104870</guid>
      <dc:creator>sjafferali</dc:creator>
      <dc:date>2018-04-20T21:13:34Z</dc:date>
    </item>
    <item>
      <title>Re: Why am I unable to convert a string to numeric?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-am-I-unable-to-convert-a-string-to-numeric/m-p/354274#M104871</link>
      <description>&lt;P&gt;The problem is usually whitespace so try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="dnr_ecc" jobname="*IC*HV_TREX"
| eval runtime = tonumber(replace(total_run_time, "[\r\n\s]+", ""))
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 20 Apr 2018 23:04:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-am-I-unable-to-convert-a-string-to-numeric/m-p/354274#M104871</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2018-04-20T23:04:25Z</dc:date>
    </item>
    <item>
      <title>Re: Why am I unable to convert a string to numeric?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-am-I-unable-to-convert-a-string-to-numeric/m-p/354275#M104872</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/107567"&gt;@sjafferali&lt;/a&gt;, can there be spaces before or after numeric total_run_time which may treat it as string? Can you try the following?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; index="dnr_ecc" jobname="*IC*HV_TREX" 
| eval total_run_time=replace(total_run_time,"\s+","")
| eval runtime = tostring(total_run_time,"duration")
| table jobname total_run_time runtime
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;PS: &lt;CODE&gt;tostring(&amp;lt;yourFieldName&amp;gt;,"duration")&lt;/CODE&gt; converts seconds to &lt;CODE&gt;days+ HH:MM:SS&lt;/CODE&gt;. If your need just numeric &lt;CODE&gt;replace()&lt;/CODE&gt; eval should do. Following is the run-anywhere example with spaces around data:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval total_run_time=" 1540 ; 1751 ; 1780 ; 1832 "
| makemv total_run_time delim=";"
| mvexpand total_run_time
| eval total_run_time=replace(total_run_time,"\s+","")
| eval runtime = tostring(total_run_time,"duration")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Sep 2020 19:09:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-am-I-unable-to-convert-a-string-to-numeric/m-p/354275#M104872</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2020-09-29T19:09:49Z</dc:date>
    </item>
    <item>
      <title>Re: Why am I unable to convert a string to numeric?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-am-I-unable-to-convert-a-string-to-numeric/m-p/354276#M104873</link>
      <description>&lt;P&gt;@sjafferali, you can use trim command to remove space, try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; index="dnr_ecc" jobname="*IC*HV_TREX"  | eval runtime = tonumber(trim(total_run_time," ")) |
 table jobname total_run_time runtime
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 21 Apr 2018 12:50:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-am-I-unable-to-convert-a-string-to-numeric/m-p/354276#M104873</guid>
      <dc:creator>TISKAR</dc:creator>
      <dc:date>2018-04-21T12:50:10Z</dc:date>
    </item>
    <item>
      <title>Re: Why am I unable to convert a string to numeric?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-am-I-unable-to-convert-a-string-to-numeric/m-p/354277#M104874</link>
      <description>&lt;P&gt;Thanks Everyone for your response and Thanks Niketnilay.&lt;/P&gt;

&lt;P&gt;The command below worked. Looks like there were blank spaces after the numbers. I was able to chart the total runtime by day which provides a trend analysis.&lt;/P&gt;

&lt;P&gt;eval total_run_time=replace(total_run_time,"\s+","")&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 19:12:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-am-I-unable-to-convert-a-string-to-numeric/m-p/354277#M104874</guid>
      <dc:creator>sjafferali</dc:creator>
      <dc:date>2020-09-29T19:12:01Z</dc:date>
    </item>
    <item>
      <title>Re: Why am I unable to convert a string to numeric?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-am-I-unable-to-convert-a-string-to-numeric/m-p/354278#M104875</link>
      <description>&lt;P&gt;Hi Somesoni2 - Thank you for your multiple immediate responses. I really appreciate your help.&lt;/P&gt;

&lt;P&gt;The command below worked for my scenario.&lt;/P&gt;

&lt;P&gt;eval total_run_time=replace(total_run_time,"\s+","")&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 19:12:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-am-I-unable-to-convert-a-string-to-numeric/m-p/354278#M104875</guid>
      <dc:creator>sjafferali</dc:creator>
      <dc:date>2020-09-29T19:12:03Z</dc:date>
    </item>
  </channel>
</rss>

