<?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 write a case statement for this condition? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-case-statement-for-this-condition/m-p/278303#M84005</link>
    <description>&lt;P&gt;My values are like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Miscellanious (Field name )
Off-line|Idle|In Service|
NCR Custom Edition v3.13 build578907|
In Service|Idle|In Service|0|0|0|0|0||030420|G531-0283|0||||
Closed|Idle|In Service|0|0||030420|G531-0283|0||||
Off-line|Idle|In Service|0|0||030420|GEEK|DATA|G531-0283|0||||
Supervisor|Idle|In Service|GEEK|DATA|G531-0283|0||||
Terminal Mode|Idle|In Service|0|0||030420|GEEK|DATA|G531-0283|0||||
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;From the above data, I need only the value before the first pipe and I need to compare and display as mentioned below ..&lt;/P&gt;

&lt;P&gt;These are my attempted approaches:&lt;/P&gt;

&lt;P&gt;If the field Miscellanious has the value as "In Service" before the first &lt;CODE&gt;|&lt;/CODE&gt; (pipe),  then output should be "In Service"&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|eval Terminal_Mode= case (Miscellanious  =="%In Service","In Service", Miscellanious =="Closed","Closed", Miscellanious =="Off-line","Off-line", Miscellanious == "Supervisor","Supervisor",  Miscellanious =="Terminal Mode","Terminal Mode", a=1,"") 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;and another one is:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval option=if(match(miscellaneous1,"In Service"),"In Service","")
| eval option1=if(match(miscellaneous1,"Closed"),"Closed","")
| eval option2=if(match(miscellaneous1,"Off-line"),"Off-line","")
| eval option3=if(match(miscellaneous1,"Supervisor"),"Supervisor","")
| eval option4=if(match(miscellaneous1,"Terminal Mode"),"Terminal Mode","")
| eval Terminal_Mode=coalesce(option,option1,option2,option3,option4)
| table Terminal_Mode.
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;But it's not working. Kindly help.&lt;BR /&gt;
Thanks in advance..&lt;/P&gt;</description>
    <pubDate>Thu, 02 Jun 2016 08:38:33 GMT</pubDate>
    <dc:creator>shankarananthth</dc:creator>
    <dc:date>2016-06-02T08:38:33Z</dc:date>
    <item>
      <title>How to write a case statement for this condition?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-case-statement-for-this-condition/m-p/278303#M84005</link>
      <description>&lt;P&gt;My values are like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Miscellanious (Field name )
Off-line|Idle|In Service|
NCR Custom Edition v3.13 build578907|
In Service|Idle|In Service|0|0|0|0|0||030420|G531-0283|0||||
Closed|Idle|In Service|0|0||030420|G531-0283|0||||
Off-line|Idle|In Service|0|0||030420|GEEK|DATA|G531-0283|0||||
Supervisor|Idle|In Service|GEEK|DATA|G531-0283|0||||
Terminal Mode|Idle|In Service|0|0||030420|GEEK|DATA|G531-0283|0||||
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;From the above data, I need only the value before the first pipe and I need to compare and display as mentioned below ..&lt;/P&gt;

&lt;P&gt;These are my attempted approaches:&lt;/P&gt;

&lt;P&gt;If the field Miscellanious has the value as "In Service" before the first &lt;CODE&gt;|&lt;/CODE&gt; (pipe),  then output should be "In Service"&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|eval Terminal_Mode= case (Miscellanious  =="%In Service","In Service", Miscellanious =="Closed","Closed", Miscellanious =="Off-line","Off-line", Miscellanious == "Supervisor","Supervisor",  Miscellanious =="Terminal Mode","Terminal Mode", a=1,"") 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;and another one is:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval option=if(match(miscellaneous1,"In Service"),"In Service","")
| eval option1=if(match(miscellaneous1,"Closed"),"Closed","")
| eval option2=if(match(miscellaneous1,"Off-line"),"Off-line","")
| eval option3=if(match(miscellaneous1,"Supervisor"),"Supervisor","")
| eval option4=if(match(miscellaneous1,"Terminal Mode"),"Terminal Mode","")
| eval Terminal_Mode=coalesce(option,option1,option2,option3,option4)
| table Terminal_Mode.
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;But it's not working. Kindly help.&lt;BR /&gt;
Thanks in advance..&lt;/P&gt;</description>
      <pubDate>Thu, 02 Jun 2016 08:38:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-case-statement-for-this-condition/m-p/278303#M84005</guid>
      <dc:creator>shankarananthth</dc:creator>
      <dc:date>2016-06-02T08:38:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a case statement for this condition?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-case-statement-for-this-condition/m-p/278304#M84006</link>
      <description>&lt;P&gt;I think you were close with your case statement.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|eval Terminal_Mode= case (match(Miscellanious,"%In Service%"),"In Service", match(Miscellanious,"Closed%"),"Closed", match(Miscellanious,"Off-line%"),"Off-line", match(Miscellanious, "Supervisor%"),"Supervisor", match(Miscellanious,"Terminal Mode%"),"Terminal Mode", 1=1,"")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 02 Jun 2016 13:03:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-case-statement-for-this-condition/m-p/278304#M84006</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2016-06-02T13:03:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a case statement for this condition?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-case-statement-for-this-condition/m-p/278305#M84007</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;If I understand correctly, the value of your Miscellanious field is the one you mentioned above, therefore, can you not just do the following:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rex field=Miscellanious "^(?&amp;lt;Terminal_Mode&amp;gt;[^\|]+)"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Or this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval Terminal_Mode = mvindex(split(Miscellanious, "|"), 0)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Let me know if that works for you.&lt;/P&gt;</description>
      <pubDate>Thu, 02 Jun 2016 13:04:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-case-statement-for-this-condition/m-p/278305#M84007</guid>
      <dc:creator>javiergn</dc:creator>
      <dc:date>2016-06-02T13:04:20Z</dc:date>
    </item>
  </channel>
</rss>

