<?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 Re: evaluate multiple fields in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/evaluate-multiple-fields/m-p/538766#M152333</link>
    <description>&lt;P&gt;I like this solution show my code clean, and yes I'm filtering my fields, "name" and 'short name" at the "index" line, thanks&lt;/P&gt;</description>
    <pubDate>Fri, 05 Feb 2021 13:43:26 GMT</pubDate>
    <dc:creator>xyz123</dc:creator>
    <dc:date>2021-02-05T13:43:26Z</dc:date>
    <item>
      <title>evaluate multiple fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/evaluate-multiple-fields/m-p/538366#M152178</link>
      <description>&lt;P&gt;Hello,&lt;BR /&gt;I have 2 fields I want to filter they are: name, "short name"&lt;BR /&gt;&lt;BR /&gt;I want to pull all the events that contains: name="software" or "short name"=software"&amp;nbsp;&lt;BR /&gt;and&amp;nbsp; exclude: "Splunk" "Adobe" "Microsoft".. and another 50 names&amp;nbsp;for both fields&lt;BR /&gt;&lt;BR /&gt;I have this for the exclusion:&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;| regex name!="(.*)((?i)(splunk|acrobat|microsoft)(.*)"
| regex "short name"!="(.*)((?i)(splunk|acrobat|microsoft)(.*)"&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;One question: is there a way to put this in 1 sentence instead of use duplication like above?&lt;BR /&gt;for example:&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; | regex (name| "short name")!="(.*)((?i)(splunk|acrobat|microsoft)(.*)"&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;xyz123&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Feb 2021 02:26:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/evaluate-multiple-fields/m-p/538366#M152178</guid>
      <dc:creator>xyz123</dc:creator>
      <dc:date>2021-02-03T02:26:32Z</dc:date>
    </item>
    <item>
      <title>Re: evaluate multiple fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/evaluate-multiple-fields/m-p/538367#M152179</link>
      <description>&lt;P&gt;You can use the 'where' command instead of regex and do&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| where !(match(name, "(.*)((?i)(splunk|acrobat|microsoft)(.*)") OR match('short name', "(.*)((?i)(splunk|acrobat|microsoft)(.*)"))&lt;/LI-CODE&gt;&lt;P&gt;Note that in a where clause, the field names have the same rules as in eval statements, i.e. for fields containing non standard characters, you need to wrap the field in single quotes&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Feb 2021 03:16:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/evaluate-multiple-fields/m-p/538367#M152179</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2021-02-03T03:16:34Z</dc:date>
    </item>
    <item>
      <title>Re: evaluate multiple fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/evaluate-multiple-fields/m-p/538370#M152182</link>
      <description>&lt;P&gt;hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/228774"&gt;@xyz123&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;If fields name and "short name" part of your index then you can filter them in the main search only. This will be much faster.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=index NOT [| makeresults | eval name="splunk|microsoft" | eval name=split(name, "|") | mvexpand name | strcat "*" name "*" name | format] NOT [| makeresults | eval filter="splunk|microsoft" | eval filter=split(filter, "|") | mvexpand filter | strcat "*" filter "*" filter | eval "short name"=filter | fields - filter | format]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For your question, if you want the same query to filter values for 2 fields, you can create a macro and use it in your search.&lt;/P&gt;&lt;P&gt;1. Create a macro with an argument.&lt;/P&gt;&lt;P&gt;macros.conf&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;[filter_software(1)]
args = fieldname
definition = | makeresults | eval filter="splunk|microsoft|dell|apple" | eval filter=split(filter, "|") | mvexpand filter | strcat "*" filter "*" filter| eval $fieldname$=filter| fields - filter| format&lt;/LI-CODE&gt;&lt;P&gt;2.&amp;nbsp; Use that macro in your search.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=indexname sorcetype=sourcetypename NOT [`filter_software("name")`] NOT [`filter_software("short name")`]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If this reply helps you, an upvote/like would be appreciated.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Feb 2021 04:48:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/evaluate-multiple-fields/m-p/538370#M152182</guid>
      <dc:creator>manjunathmeti</dc:creator>
      <dc:date>2021-02-03T04:48:01Z</dc:date>
    </item>
    <item>
      <title>Re: evaluate multiple fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/evaluate-multiple-fields/m-p/538766#M152333</link>
      <description>&lt;P&gt;I like this solution show my code clean, and yes I'm filtering my fields, "name" and 'short name" at the "index" line, thanks&lt;/P&gt;</description>
      <pubDate>Fri, 05 Feb 2021 13:43:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/evaluate-multiple-fields/m-p/538766#M152333</guid>
      <dc:creator>xyz123</dc:creator>
      <dc:date>2021-02-05T13:43:26Z</dc:date>
    </item>
    <item>
      <title>Re: evaluate multiple fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/evaluate-multiple-fields/m-p/538767#M152334</link>
      <description>&lt;P&gt;I tried, this but since they are around more than 50 "name" it's going to take a lot of code that's why I went using RegEx, thanks so much for your reply.&lt;/P&gt;</description>
      <pubDate>Fri, 05 Feb 2021 13:45:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/evaluate-multiple-fields/m-p/538767#M152334</guid>
      <dc:creator>xyz123</dc:creator>
      <dc:date>2021-02-05T13:45:04Z</dc:date>
    </item>
  </channel>
</rss>

