<?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 String Comparison with Foreach in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/String-Comparison-with-Foreach/m-p/383923#M171105</link>
    <description>&lt;P&gt;I have a  lookup table from a csv that looks like this&lt;/P&gt;

&lt;P&gt;name exam1 exam2   exam3&lt;BR /&gt;
john   good    bad        bad&lt;BR /&gt;
peter  bad      bad        best&lt;BR /&gt;
ken     best     bad         bad&lt;/P&gt;

&lt;P&gt;and  the list continues with almost 100 rows.&lt;BR /&gt;
I want to know whether there is a 'best' under each exam.&lt;BR /&gt;
So, I am thinking to implement foreach , which should give  us a result something like this,&lt;/P&gt;

&lt;P&gt;exam1 OK&lt;BR /&gt;
exam2  NO&lt;BR /&gt;
exam3 OK&lt;BR /&gt;
(because for exam1 and exam3 there was atleast someone who performed 'best' but for exam2 no one has 'best'&lt;/P&gt;

&lt;P&gt;This is what I tried&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| inputlookup exam.csv 
| foreach * [eval final = if(&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;=="best","OK","NO")]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;But I can't make the command work. &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 21 May 2019 15:54:16 GMT</pubDate>
    <dc:creator>zacksoft</dc:creator>
    <dc:date>2019-05-21T15:54:16Z</dc:date>
    <item>
      <title>String Comparison with Foreach</title>
      <link>https://community.splunk.com/t5/Splunk-Search/String-Comparison-with-Foreach/m-p/383923#M171105</link>
      <description>&lt;P&gt;I have a  lookup table from a csv that looks like this&lt;/P&gt;

&lt;P&gt;name exam1 exam2   exam3&lt;BR /&gt;
john   good    bad        bad&lt;BR /&gt;
peter  bad      bad        best&lt;BR /&gt;
ken     best     bad         bad&lt;/P&gt;

&lt;P&gt;and  the list continues with almost 100 rows.&lt;BR /&gt;
I want to know whether there is a 'best' under each exam.&lt;BR /&gt;
So, I am thinking to implement foreach , which should give  us a result something like this,&lt;/P&gt;

&lt;P&gt;exam1 OK&lt;BR /&gt;
exam2  NO&lt;BR /&gt;
exam3 OK&lt;BR /&gt;
(because for exam1 and exam3 there was atleast someone who performed 'best' but for exam2 no one has 'best'&lt;/P&gt;

&lt;P&gt;This is what I tried&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| inputlookup exam.csv 
| foreach * [eval final = if(&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;=="best","OK","NO")]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;But I can't make the command work. &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 21 May 2019 15:54:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/String-Comparison-with-Foreach/m-p/383923#M171105</guid>
      <dc:creator>zacksoft</dc:creator>
      <dc:date>2019-05-21T15:54:16Z</dc:date>
    </item>
    <item>
      <title>Re: String Comparison with Foreach</title>
      <link>https://community.splunk.com/t5/Splunk-Search/String-Comparison-with-Foreach/m-p/383924#M171106</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;

&lt;P&gt;Give a try&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| inputlookup sample.csv 
| stats list(exam1) as exam1,list(exam2) as exam2,list(exam3) as exam3 
| eval exam1 = if(tostring((mvfind(exam1,"best")))!="Null","OK","NO"), exam2 = if(tostring((mvfind(exam2,"best")))!="Null","OK","NO"), exam3 = if(tostring((mvfind(exam3,"best")))!="Null","OK","NO") 
| transpose 
| rename column as Exams,"row 1" as Results
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;OR&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| inputlookup sample.csv 
| transpose column_name=Exams 
| search Exams != name 
| eval final = 'row 1'.",".'row 2' .",". 'row 3' 
| makemv delim="," final 
| eval final= if(tostring((mvfind(final,"best")))!="Null","OK","NO") 
| table Exams, final
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 22 May 2019 05:53:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/String-Comparison-with-Foreach/m-p/383924#M171106</guid>
      <dc:creator>vnravikumar</dc:creator>
      <dc:date>2019-05-22T05:53:27Z</dc:date>
    </item>
  </channel>
</rss>

