<?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: How to edit my search to format String to Number with fieldformat for all 60 columns? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-format-String-to-Number-with/m-p/344945#M102190</link>
    <description>&lt;P&gt;You need &lt;CODE&gt;foreach&lt;/CODE&gt; command for that.&lt;BR /&gt;
 Like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; &amp;lt;search&amp;gt; | foreach test*a [fieldformat "&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;"=tonumber('&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;')
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 24 Apr 2017 15:37:06 GMT</pubDate>
    <dc:creator>somesoni2</dc:creator>
    <dc:date>2017-04-24T15:37:06Z</dc:date>
    <item>
      <title>How to edit my search to format String to Number with fieldformat for all 60 columns?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-format-String-to-Number-with/m-p/344944#M102189</link>
      <description>&lt;P&gt;Hey guys &lt;BR /&gt;
Is there a quick way to format data?&lt;BR /&gt;
I want to format data like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;search&amp;gt; |fieldformat test1a=tonumber(test1a)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;It works but I have more than 60 columns to do&lt;/P&gt;

&lt;P&gt;so I try this  &lt;CODE&gt;&amp;lt;search&amp;gt; |fieldformat test*a=tonumber(test*a)&lt;/CODE&gt;&lt;BR /&gt;
it's not any change to data&lt;/P&gt;

&lt;P&gt;column have test1a test2a test3a test4a ... do1t do2t do3t do4t ...... ss1r ss2r ss3r ss4r ... and so on&lt;BR /&gt;
This data are Scientific notation data&lt;BR /&gt;
If I do Regular Expression I will type more than 20 row &lt;/P&gt;

&lt;P&gt;Does any suggest quick format data?&lt;/P&gt;

&lt;P&gt;Thanks you for anyway.&lt;/P&gt;</description>
      <pubDate>Mon, 24 Apr 2017 15:19:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-format-String-to-Number-with/m-p/344944#M102189</guid>
      <dc:creator>laudai</dc:creator>
      <dc:date>2017-04-24T15:19:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to edit my search to format String to Number with fieldformat for all 60 columns?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-format-String-to-Number-with/m-p/344945#M102190</link>
      <description>&lt;P&gt;You need &lt;CODE&gt;foreach&lt;/CODE&gt; command for that.&lt;BR /&gt;
 Like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; &amp;lt;search&amp;gt; | foreach test*a [fieldformat "&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;"=tonumber('&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;')
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 24 Apr 2017 15:37:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-format-String-to-Number-with/m-p/344945#M102190</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2017-04-24T15:37:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to edit my search to format String to Number with fieldformat for all 60 columns?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-format-String-to-Number-with/m-p/344946#M102191</link>
      <description>&lt;P&gt;HI somesoni2  thank you for your answer.&lt;/P&gt;

&lt;P&gt;I meet some problem in splunk string,number&lt;/P&gt;

&lt;P&gt;For example:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|eval test="123.4E-3" |fieldformat test=tonumber(test)|table test
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;your test will get 0.1234&lt;/P&gt;

&lt;P&gt;If you text like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|eval total=0 | eval test1="1.2000E-3" | eval test2="2.4000E-3" |eval test3=3.6000E-3
|foreach test* [fieldformat &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;=tonumber(&amp;lt;FIELD&amp;gt;)]
|foreach test* [eval total=total+&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;]
|table test*,total
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;test1          test2           test3            total&lt;BR /&gt;
1.2000E-3   2.4000E-3   0.0036000   0.0072000&lt;/P&gt;

&lt;P&gt;In this case test1 test2 test3 are numbers  so you can add them together,even you Double quotes numbers.&lt;BR /&gt;
You can see the column is number or text with right-justified or left-justified&lt;/P&gt;

&lt;P&gt;How can I tell a field value's type (number or string) just by looking?&lt;BR /&gt;
&lt;A href="https://answers.splunk.com/answers/241582/how-can-i-tell-a-field-values-type-number-or-strin.html"&gt;https://answers.splunk.com/answers/241582/how-can-i-tell-a-field-values-type-number-or-strin.html&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;or you can use isnum() isstr() to check type&lt;/P&gt;

&lt;P&gt;In Splunk you can test like this to confirm column type&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|eval total=0 | eval test1="1.2000E-3" | eval test2="2.4000E-3" |eval test3=3.6000E-3 |eval test4="12" |eval testd="12d"
|eval 1isnum=if(isNum(test1),"true","false")
|eval 2isnum=if(isNum(test2),"true","false")
|eval 3isnum=if(isNum(test3),"true","false")
|eval 4isnum=if(isNum(test4),"true","false")
|eval disnum=if(isNum(testd),"true","false")
|eval 1isstr=if(isstr(test1),"true","false")
|eval 2isstr=if(isstr(test2),"true","false")
|eval 3isstr=if(isstr(test3),"true","false")
|eval 4isstr=if(isstr(test4),"true","false")
|eval disstr=if(isstr(testd),"true","false")
|table 1* 2* 3* 4* d* 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;in this case test1~4 are number and string &lt;BR /&gt;
your will get :&lt;BR /&gt;
1isnum  1isstr  2isnum  2isstr  3isnum  3isstr  4isnum  4isstr  disnum  disstr&lt;BR /&gt;
true            true            true           true         true           true        true        true        false           true&lt;/P&gt;

&lt;P&gt;Why are fields returning true for both isNum() and isStr() &lt;BR /&gt;
&lt;A href="https://answers.splunk.com/answers/241582/how-can-i-tell-a-field-values-type-number-or-strin.html"&gt;https://answers.splunk.com/answers/241582/how-can-i-tell-a-field-values-type-number-or-strin.html&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Is foreach is a bug to use tonumber? &lt;/P&gt;

&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Wed, 26 Apr 2017 10:08:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-format-String-to-Number-with/m-p/344946#M102191</guid>
      <dc:creator>laudai</dc:creator>
      <dc:date>2017-04-26T10:08:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to edit my search to format String to Number with fieldformat for all 60 columns?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-format-String-to-Number-with/m-p/344947#M102192</link>
      <description>&lt;P&gt;The tonumber() function will make the field into a number if it possibly can.&lt;/P&gt;

&lt;P&gt;This function converts the input string NUMSTR to a number. NUMSTR can be a field name or a value. BASE &lt;BR /&gt;
is optional and used to define the base of the number to convert to. BASE can be 2 to 36, and defaults to 10. If the tonumber function cannot parse a field value to a number, for example if the value contains a leading and trailing space, the function returns NULL. Use the trim function to remove leading or trailing spaces. If the tonumber function cannot parse a literal string to a number, it returns an error.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults  | eval total=0 | eval test1="1.2000E-3" | eval test2="2.4000E-3" 
| eval test3=3.6000E-3 | eval test4="12" | eval testd="12d" 
| foreach test* 
    [ eval &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;.beforetype = typeof(&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;) 
    | eval &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt; = tonumber(&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;) 
    |  eval &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;.aftertype = typeof(&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;) 
    | eval total=total+if(isnum(&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;),&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;,0)
    ] 
| table test* total
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;As far as your isstr() question, it appears that "num" is a subset of "string" in splunk's implementation.  That's not unheard of in token-oriented languages -- i wonder what else other than "null()" is NOT a string -- although it's unfamiliar if you are coming from the C/Java world.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Apr 2017 16:23:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-format-String-to-Number-with/m-p/344947#M102192</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-04-26T16:23:03Z</dc:date>
    </item>
  </channel>
</rss>

