<?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 Conditional searching using eval command  with if match in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Conditional-searching-using-eval-command-with-if-match/m-p/488074#M193887</link>
    <description>&lt;P&gt;Hi SMEs:&lt;/P&gt;

&lt;P&gt;I would like to define a print event type to differentiate Remote Prints from Office Print jobs.&lt;/P&gt;

&lt;P&gt;From my print logs, i'd like to:&lt;/P&gt;

&lt;P&gt;Define channel = "Remote Print",  where printer name contains "&lt;EM&gt;WING*RCA&lt;/EM&gt;" else, "Office Print". &lt;/P&gt;

&lt;P&gt;I started off with:&lt;BR /&gt;
| eval channel = if(match(like printer="&lt;EM&gt;WING*RCA&lt;/EM&gt;", "Remote Print"), "Office Print")&lt;/P&gt;

&lt;P&gt;I'm still relatively new to these commands and would appreciate any assistance.&lt;/P&gt;

&lt;P&gt;Thanks in advance,&lt;BR /&gt;
Mac&lt;/P&gt;</description>
    <pubDate>Wed, 30 Sep 2020 04:30:19 GMT</pubDate>
    <dc:creator>mdeterville</dc:creator>
    <dc:date>2020-09-30T04:30:19Z</dc:date>
    <item>
      <title>Conditional searching using eval command  with if match</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Conditional-searching-using-eval-command-with-if-match/m-p/488074#M193887</link>
      <description>&lt;P&gt;Hi SMEs:&lt;/P&gt;

&lt;P&gt;I would like to define a print event type to differentiate Remote Prints from Office Print jobs.&lt;/P&gt;

&lt;P&gt;From my print logs, i'd like to:&lt;/P&gt;

&lt;P&gt;Define channel = "Remote Print",  where printer name contains "&lt;EM&gt;WING*RCA&lt;/EM&gt;" else, "Office Print". &lt;/P&gt;

&lt;P&gt;I started off with:&lt;BR /&gt;
| eval channel = if(match(like printer="&lt;EM&gt;WING*RCA&lt;/EM&gt;", "Remote Print"), "Office Print")&lt;/P&gt;

&lt;P&gt;I'm still relatively new to these commands and would appreciate any assistance.&lt;/P&gt;

&lt;P&gt;Thanks in advance,&lt;BR /&gt;
Mac&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 04:30:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Conditional-searching-using-eval-command-with-if-match/m-p/488074#M193887</guid>
      <dc:creator>mdeterville</dc:creator>
      <dc:date>2020-09-30T04:30:19Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional searching using eval command  with if match</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Conditional-searching-using-eval-command-with-if-match/m-p/488075#M193888</link>
      <description>&lt;P&gt;If the name is WING[digit]RCA you can go with&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval raw = "Printer1%WING1RCA%;Printer2%WING2RCA;Printer3%WING;Printer4%RCA" 
| makemv raw delim=";" 
| mvexpand raw 
| rex field=raw "(?P&amp;lt;Printer&amp;gt;[^\%]+)%(?P&amp;lt;Location&amp;gt;[^\%]+)" 
| eval channel = if(match(Location, "WING\dRCA"), "Remote Office", "Office")
| table Printer Location channel
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If there is more text in between, WING[text]RCA, you can break it down to &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval channel = if(match(Location, "WING.*"), if(match(Location, ".*RCA"), "Remote Office", "Office"), "Office")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 06 Mar 2020 02:25:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Conditional-searching-using-eval-command-with-if-match/m-p/488075#M193888</guid>
      <dc:creator>anmolpatel</dc:creator>
      <dc:date>2020-03-06T02:25:42Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional searching using eval command  with if match</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Conditional-searching-using-eval-command-with-if-match/m-p/488076#M193889</link>
      <description>&lt;P&gt;Thanks anmol. &lt;/P&gt;

&lt;P&gt;The printer name typically looks like eg. Canon MF4770n (from WING_000.0.000.0-RCA).&lt;/P&gt;</description>
      <pubDate>Fri, 06 Mar 2020 02:50:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Conditional-searching-using-eval-command-with-if-match/m-p/488076#M193889</guid>
      <dc:creator>mdeterville</dc:creator>
      <dc:date>2020-03-06T02:50:06Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional searching using eval command  with if match</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Conditional-searching-using-eval-command-with-if-match/m-p/488077#M193890</link>
      <description>&lt;P&gt;If the printer is an extracted key, the solution i've provided above will solve your query. Just change the variables as required. &lt;/P&gt;</description>
      <pubDate>Fri, 06 Mar 2020 03:05:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Conditional-searching-using-eval-command-with-if-match/m-p/488077#M193890</guid>
      <dc:creator>anmolpatel</dc:creator>
      <dc:date>2020-03-06T03:05:50Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional searching using eval command  with if match</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Conditional-searching-using-eval-command-with-if-match/m-p/488078#M193891</link>
      <description>&lt;P&gt;You can use both like and match functions with eval command to &lt;/P&gt;

&lt;OL&gt;
&lt;LI&gt;&lt;P&gt;&lt;STRONG&gt;like(FIELD, PATTERN)&lt;/STRONG&gt;&lt;BR /&gt;
This function returns TRUE if FIELD values matches the PATTERN.&lt;BR /&gt;
In PATTERN, you can use use the percent ( % ) symbol as a wildcard for multiple characters and use the underscore ( _ ) character for a single character match.&lt;/P&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;P&gt;&lt;STRONG&gt;match(FIELD, "REGEX")&lt;/STRONG&gt;&lt;BR /&gt;
This is is regex based function and returns TRUE or FALSE based on whether REGEX matches FIELD values.&lt;/P&gt;&lt;/LI&gt;
&lt;/OL&gt;

&lt;P&gt;So both queries below returns same results:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults | eval printer ="Canon MF4770n (from WING_000.0.000.0-RCA)" | eval channel = if(match(printer, "WING.*RCA"), "Remote Print", "Office Print")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults | eval printer ="Canon MF4770n (from WING_000.0.000.0-RCA)" | eval channel = if(like(printer, "%WING%RCA%"), "Remote Print", "Office Print")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 06 Mar 2020 07:35:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Conditional-searching-using-eval-command-with-if-match/m-p/488078#M193891</guid>
      <dc:creator>manjunathmeti</dc:creator>
      <dc:date>2020-03-06T07:35:42Z</dc:date>
    </item>
  </channel>
</rss>

