<?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 Why Isn't My String Value (a multivalue field) Being Converted to a Number? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Why-Isn-t-My-String-Value-a-multivalue-field-Being-Converted-to/m-p/482956#M135247</link>
    <description>&lt;P&gt;Hello,&lt;BR /&gt;
I've checked many of the Answers pages, but to no avail.&lt;/P&gt;

&lt;P&gt;In my table, the value "appears" to be converted from a string to a number. However, in the Interesting Fields, it still appears as alphanumeric.&lt;/P&gt;

&lt;P&gt;Here is one line of the event which contains the data I want to convert from string to number.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;    SAG.TXT           |          100 B |    6.5 KB/s | ascii  | 100%
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Not concerned with the 1st, 4th, or 5th value in this event. Only &lt;STRONG&gt;100 B&lt;/STRONG&gt; and &lt;STRONG&gt;6.5 KB/s&lt;/STRONG&gt;. These have been regexed in props.conf.&lt;BR /&gt;
file_size=100 B&lt;BR /&gt;
file_transfer_rate=6.5 KB/s&lt;/P&gt;

&lt;P&gt;Here is my SPL.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;host=host1
| rex field=file_size "(?&amp;lt;fileSize&amp;gt;\d*)\s"
| rex field=file_transfer_rate "(?&amp;lt;fileTransRate&amp;gt;\d*.\d{1,6})"

| eval fs1=trim(fileSize)
| eval fs2=tonumber(trim(fileSize))
| convert rmunit(file_size) AS fs3

| table file_size, fileSize, fs1, fs2, fs3
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Here are the results.&lt;BR /&gt;
&lt;IMG src="https://community.splunk.com/storage/temp/284581-screenshot-2-25-2020-5-04-28-pm.png" alt="alt text" /&gt;&lt;/P&gt;

&lt;P&gt;file_size is a string&lt;BR /&gt;
fileSize &lt;STRONG&gt;appears&lt;/STRONG&gt; to a number&lt;BR /&gt;
fs1 &lt;STRONG&gt;appears&lt;/STRONG&gt; to a number&lt;BR /&gt;
fs2 is blank&lt;BR /&gt;
fs3 &lt;STRONG&gt;appears&lt;/STRONG&gt; to a number&lt;/P&gt;

&lt;P&gt;However, here are the Interesting Fields.&lt;BR /&gt;
&lt;IMG src="https://community.splunk.com/storage/temp/284582-screenshot-2-25-2020-5-08-23-pm.png" alt="alt text" /&gt;&lt;/P&gt;

&lt;P&gt;All of them are alphanumeric, and fs2 is not present.&lt;/P&gt;

&lt;P&gt;Thanks in advance for any guidance.&lt;BR /&gt;
God bless,&lt;BR /&gt;
Genesius&lt;/P&gt;

&lt;P&gt;UPDATE&lt;BR /&gt;
I have not worked with multivalue fields before. I didn't know that certain commands will not work on multivalue fields. Apologies for not mentioning in the original post.&lt;/P&gt;

&lt;P&gt;Any ideas with this new information?&lt;/P&gt;</description>
    <pubDate>Wed, 30 Sep 2020 04:24:49 GMT</pubDate>
    <dc:creator>genesiusj</dc:creator>
    <dc:date>2020-09-30T04:24:49Z</dc:date>
    <item>
      <title>Why Isn't My String Value (a multivalue field) Being Converted to a Number?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-Isn-t-My-String-Value-a-multivalue-field-Being-Converted-to/m-p/482956#M135247</link>
      <description>&lt;P&gt;Hello,&lt;BR /&gt;
I've checked many of the Answers pages, but to no avail.&lt;/P&gt;

&lt;P&gt;In my table, the value "appears" to be converted from a string to a number. However, in the Interesting Fields, it still appears as alphanumeric.&lt;/P&gt;

&lt;P&gt;Here is one line of the event which contains the data I want to convert from string to number.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;    SAG.TXT           |          100 B |    6.5 KB/s | ascii  | 100%
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Not concerned with the 1st, 4th, or 5th value in this event. Only &lt;STRONG&gt;100 B&lt;/STRONG&gt; and &lt;STRONG&gt;6.5 KB/s&lt;/STRONG&gt;. These have been regexed in props.conf.&lt;BR /&gt;
file_size=100 B&lt;BR /&gt;
file_transfer_rate=6.5 KB/s&lt;/P&gt;

&lt;P&gt;Here is my SPL.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;host=host1
| rex field=file_size "(?&amp;lt;fileSize&amp;gt;\d*)\s"
| rex field=file_transfer_rate "(?&amp;lt;fileTransRate&amp;gt;\d*.\d{1,6})"

| eval fs1=trim(fileSize)
| eval fs2=tonumber(trim(fileSize))
| convert rmunit(file_size) AS fs3

| table file_size, fileSize, fs1, fs2, fs3
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Here are the results.&lt;BR /&gt;
&lt;IMG src="https://community.splunk.com/storage/temp/284581-screenshot-2-25-2020-5-04-28-pm.png" alt="alt text" /&gt;&lt;/P&gt;

&lt;P&gt;file_size is a string&lt;BR /&gt;
fileSize &lt;STRONG&gt;appears&lt;/STRONG&gt; to a number&lt;BR /&gt;
fs1 &lt;STRONG&gt;appears&lt;/STRONG&gt; to a number&lt;BR /&gt;
fs2 is blank&lt;BR /&gt;
fs3 &lt;STRONG&gt;appears&lt;/STRONG&gt; to a number&lt;/P&gt;

&lt;P&gt;However, here are the Interesting Fields.&lt;BR /&gt;
&lt;IMG src="https://community.splunk.com/storage/temp/284582-screenshot-2-25-2020-5-08-23-pm.png" alt="alt text" /&gt;&lt;/P&gt;

&lt;P&gt;All of them are alphanumeric, and fs2 is not present.&lt;/P&gt;

&lt;P&gt;Thanks in advance for any guidance.&lt;BR /&gt;
God bless,&lt;BR /&gt;
Genesius&lt;/P&gt;

&lt;P&gt;UPDATE&lt;BR /&gt;
I have not worked with multivalue fields before. I didn't know that certain commands will not work on multivalue fields. Apologies for not mentioning in the original post.&lt;/P&gt;

&lt;P&gt;Any ideas with this new information?&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 04:24:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-Isn-t-My-String-Value-a-multivalue-field-Being-Converted-to/m-p/482956#M135247</guid>
      <dc:creator>genesiusj</dc:creator>
      <dc:date>2020-09-30T04:24:49Z</dc:date>
    </item>
    <item>
      <title>Re: Why Isn't My String Value (a multivalue field) Being Converted to a Number?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-Isn-t-My-String-Value-a-multivalue-field-Being-Converted-to/m-p/482957#M135248</link>
      <description>&lt;P&gt;Just use convert command with rmunit function, rmunit looks for numbers at the beginning of the value and removes trailing text and provides output in numerical values.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;host=host1 | convert rmunit(file_size) AS fileSize, rmunit(file_transfer_rate) AS fileTransRate
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 26 Feb 2020 10:06:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-Isn-t-My-String-Value-a-multivalue-field-Being-Converted-to/m-p/482957#M135248</guid>
      <dc:creator>manjunathmeti</dc:creator>
      <dc:date>2020-02-26T10:06:57Z</dc:date>
    </item>
    <item>
      <title>Re: Why Isn't My String Value (a multivalue field) Being Converted to a Number?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-Isn-t-My-String-Value-a-multivalue-field-Being-Converted-to/m-p/482958#M135249</link>
      <description>&lt;P&gt;@ to4kawa and @manjunathmeti &lt;BR /&gt;
Thank you for your answers. I updated my original post adding that these are multi-value fields.&lt;/P&gt;

&lt;P&gt;I found these two posts to be very helpful.&lt;/P&gt;

&lt;P&gt;&lt;A href="https://answers.splunk.com/answers/123887/how-to-expand-multiple-multivalue-fields.html"&gt;How to expand multiple multivalue fields?&lt;/A&gt;&lt;BR /&gt;
&lt;A href="https://answers.splunk.com/answers/737001/how-do-you-mvzip-more-than-one-field.html"&gt;How do you MVZIP more than one field?&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Using a combination of these posts, I came up with this final code.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;host=host1
| eval zipped=mvzip(file_name,mvzip(file_size,mvzip(file_transfer_rate,file_percent_complete,"##"),"##"),"##")

| mvexpand zipped
| rex field=zipped "(?&amp;lt;mvFileName&amp;gt;.*)##(?&amp;lt;mvFileSize1&amp;gt;.*)##(?&amp;lt;mvFileTransRate1&amp;gt;.*)##(?&amp;lt;mvFilePercComp&amp;gt;.*)"

| rex field=mvFileSize1 "(?&amp;lt;mvFileSize2&amp;gt;\d*)\s(?&amp;lt;mvByteUnit1&amp;gt;\w{1,2})"
| rex field=mvFileTransRate1 "(?&amp;lt;mvFileTransRate2&amp;gt;\d*.\d{1,6})\s(?&amp;lt;mvByteUnit2&amp;gt;\w{1,2}\/s)"

| eval fileSizeNum=tonumber(trim(mvFileSize2))
| eval fileTransRateNum=tonumber(trim(mvFileTransRate2))

| eval fileSizeNum2=case(mvByteUnit1="KB",fileSizeNum*1024,mvByteUnit1="B",fileSizeNum)
| eval fileTransRateNum2=fileTransRateNum*1024

| eval transTime1=fileSizeNum/fileTransRateNum
| eval transTime2=round(transTime1,2)

| eval "Event Time"=strftime(_time,"%c")

| rename mvFileName AS "File Name", transTime2 AS "Transfer Time (sec)", mvFileSize1 AS "File Size", mvFileTransRate1 AS "Transfer Rate", mvFilePercComp AS "% Complete"

| table "Event Time", "File Name", "Transfer Time (sec)", "File Size", "Transfer Rate", "% Complete" 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thanks and God bless,&lt;BR /&gt;
Genesius&lt;/P&gt;</description>
      <pubDate>Wed, 26 Feb 2020 16:27:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-Isn-t-My-String-Value-a-multivalue-field-Being-Converted-to/m-p/482958#M135249</guid>
      <dc:creator>genesiusj</dc:creator>
      <dc:date>2020-02-26T16:27:13Z</dc:date>
    </item>
  </channel>
</rss>

