<?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 grep -f over multiple fields in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/grep-f-over-multiple-fields/m-p/297091#M162844</link>
    <description>&lt;P&gt;i'm trying to do something similar to grep -f over multiple sourcetypes that i've appended together into one search.&lt;/P&gt;

&lt;P&gt;Example: index=xyz sourcetype=watchlist | fields name&lt;BR /&gt;
looks like this&lt;/P&gt;

&lt;P&gt;zeng&lt;BR /&gt;
smith&lt;BR /&gt;
willi&lt;BR /&gt;
johns&lt;BR /&gt;
charl&lt;/P&gt;

&lt;P&gt;the sourcetypes i want to search may contain any of these fields: username, lastname, fullname &lt;BR /&gt;
and i want to find all the name values in the watchlist in any of  username or lastname or fullname or any other field in those events&lt;/P&gt;

&lt;P&gt;i thought subsearches would work but the field name in the watchlist differ from the multiple field names in the other sourcetypes, and it's not an = search, it's a wildcard match search.&lt;/P&gt;</description>
    <pubDate>Fri, 16 Feb 2018 23:09:53 GMT</pubDate>
    <dc:creator>murhammr</dc:creator>
    <dc:date>2018-02-16T23:09:53Z</dc:date>
    <item>
      <title>grep -f over multiple fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/grep-f-over-multiple-fields/m-p/297091#M162844</link>
      <description>&lt;P&gt;i'm trying to do something similar to grep -f over multiple sourcetypes that i've appended together into one search.&lt;/P&gt;

&lt;P&gt;Example: index=xyz sourcetype=watchlist | fields name&lt;BR /&gt;
looks like this&lt;/P&gt;

&lt;P&gt;zeng&lt;BR /&gt;
smith&lt;BR /&gt;
willi&lt;BR /&gt;
johns&lt;BR /&gt;
charl&lt;/P&gt;

&lt;P&gt;the sourcetypes i want to search may contain any of these fields: username, lastname, fullname &lt;BR /&gt;
and i want to find all the name values in the watchlist in any of  username or lastname or fullname or any other field in those events&lt;/P&gt;

&lt;P&gt;i thought subsearches would work but the field name in the watchlist differ from the multiple field names in the other sourcetypes, and it's not an = search, it's a wildcard match search.&lt;/P&gt;</description>
      <pubDate>Fri, 16 Feb 2018 23:09:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/grep-f-over-multiple-fields/m-p/297091#M162844</guid>
      <dc:creator>murhammr</dc:creator>
      <dc:date>2018-02-16T23:09:53Z</dc:date>
    </item>
    <item>
      <title>Re: grep -f over multiple fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/grep-f-over-multiple-fields/m-p/297092#M162845</link>
      <description>&lt;P&gt;If I understood correctly you have multiple sourcetypes ...if you have one index pointing multiple sourcetypes then you can try like: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=&amp;lt;indexname&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;and if you have different sourcetype pointing different index then try like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=&amp;lt;indexname1&amp;gt; sourcetype=&amp;lt;sourcetype_name1&amp;gt; OR (index=&amp;lt;indexname2&amp;gt; sourcetype=&amp;lt;sourcetype_name2&amp;gt;)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;and if you want to find particular name (abc)  contain any of these fields: username, lastname, fullname then you can try like function&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;...|eval matchTest=case((like(username, "%abc%")), "matched",(like(lastname, "%abc%")),"matched",(like(fullname, "%abc%")),"matched",1=1,"notMatched")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 17 Feb 2018 00:33:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/grep-f-over-multiple-fields/m-p/297092#M162845</guid>
      <dc:creator>493669</dc:creator>
      <dc:date>2018-02-17T00:33:03Z</dc:date>
    </item>
    <item>
      <title>Re: grep -f over multiple fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/grep-f-over-multiple-fields/m-p/297093#M162846</link>
      <description>&lt;P&gt;If you know that the value you're looking for is already extracted into a field, and you need to verify that the value exists in a field (but you don't want to define a list of all possible fields), something like this run anywhere search should work for you:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults | eval firstname="personA"
| append [| makeresults | eval lastname="personA"]
| append [| makeresults | eval firstname="personB"]
| append [| makeresults | eval anyfieldname="personA"]
| foreach * [ eval found=if(&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;="personA", "YES", found)]
| search found="YES"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The logic is all in the last two lines, making use of the &lt;CODE&gt;foreach&lt;/CODE&gt; command to iterate through all fields to find a match.  In my example I have it looking for the value &lt;CODE&gt;personA&lt;/CODE&gt; in any field.&lt;/P&gt;</description>
      <pubDate>Sat, 17 Feb 2018 00:40:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/grep-f-over-multiple-fields/m-p/297093#M162846</guid>
      <dc:creator>micahkemp</dc:creator>
      <dc:date>2018-02-17T00:40:46Z</dc:date>
    </item>
    <item>
      <title>Re: grep -f over multiple fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/grep-f-over-multiple-fields/m-p/297094#M162847</link>
      <description>&lt;P&gt;thanks!  this was the basis for my solution.  the multivalue field result will contain a yes if any of that event's fields is a match.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults | eval name5="son" | eval firstname="personA" 
| append     [| makeresults     | eval name5="sonA"     | eval lastname="personA"] 
| append     [| makeresults     | eval name5="sonA"     | eval firstname="personB"] 
| append     [| makeresults     | eval name5="per"     | eval anyfieldname="personA"] 
| eval result="" 
| foreach *name 
    [ eval result=if(like('&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;',"%".name5."%"),result + " yes", result + " no") ] 
| makemv   result |search result=yes
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 19 Feb 2018 18:29:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/grep-f-over-multiple-fields/m-p/297094#M162847</guid>
      <dc:creator>murhammr</dc:creator>
      <dc:date>2018-02-19T18:29:07Z</dc:date>
    </item>
  </channel>
</rss>

