<?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 How to run a second command inside the if statment in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-run-a-second-command-inside-the-if-statment/m-p/592432#M206197</link>
    <description>&lt;P&gt;I have a value that could be N/A or a number. The issue is when it is a number, splunk is not picking it up as one.&lt;/P&gt;&lt;P&gt;So I have to run the "convert" command. But I need to check first if it is a N/A.&lt;/P&gt;&lt;P&gt;Below is what I have but it does not work - any ideas?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval T_CpuPerc = if(T_CpuPerc="N/A",T_CpuPerc,convert num(T_CpuPerc) )&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 05 Apr 2022 13:43:18 GMT</pubDate>
    <dc:creator>robertlynch2020</dc:creator>
    <dc:date>2022-04-05T13:43:18Z</dc:date>
    <item>
      <title>How to run a second command inside the if statment</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-run-a-second-command-inside-the-if-statment/m-p/592432#M206197</link>
      <description>&lt;P&gt;I have a value that could be N/A or a number. The issue is when it is a number, splunk is not picking it up as one.&lt;/P&gt;&lt;P&gt;So I have to run the "convert" command. But I need to check first if it is a N/A.&lt;/P&gt;&lt;P&gt;Below is what I have but it does not work - any ideas?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval T_CpuPerc = if(T_CpuPerc="N/A",T_CpuPerc,convert num(T_CpuPerc) )&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Apr 2022 13:43:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-run-a-second-command-inside-the-if-statment/m-p/592432#M206197</guid>
      <dc:creator>robertlynch2020</dc:creator>
      <dc:date>2022-04-05T13:43:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to run a second command inside the if statment</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-run-a-second-command-inside-the-if-statment/m-p/592448#M206204</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/141978"&gt;@robertlynch2020&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;if an eval statement you cannot insert a command but only a function (SPL isn't a procedural language!), so if you want to format the number in T_CpuPerc you have to use a formatting function and not the convert command.&lt;/P&gt;&lt;P&gt;In other words, try something like this:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval T_CpuPerc = if(T_CpuPerc="N/A",T_CpuPerc,tonumber(T_CpuPerc))&lt;/LI-CODE&gt;&lt;P&gt;or another function like tostring, round, etc...&lt;/P&gt;&lt;P&gt;Ciao.&lt;/P&gt;&lt;P&gt;Giuseppe&lt;/P&gt;</description>
      <pubDate>Tue, 05 Apr 2022 14:14:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-run-a-second-command-inside-the-if-statment/m-p/592448#M206204</guid>
      <dc:creator>gcusello</dc:creator>
      <dc:date>2022-04-05T14:14:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to run a second command inside the if statment</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-run-a-second-command-inside-the-if-statment/m-p/592450#M206205</link>
      <description>&lt;P&gt;brilliant - thanks&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Apr 2022 14:29:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-run-a-second-command-inside-the-if-statment/m-p/592450#M206205</guid>
      <dc:creator>robertlynch2020</dc:creator>
      <dc:date>2022-04-05T14:29:08Z</dc:date>
    </item>
  </channel>
</rss>

