<?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 Use input file to create a search and use a match command in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/Use-input-file-to-create-a-search-and-use-a-match-command/m-p/31613#M5557</link>
    <description>&lt;P&gt;I have a csv file with the following companies&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;ATT
LV3
MCI
QST
SPT
VZB
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Since the companies can change frequently, I would like to use that file to create a search that basically accomplishes the following&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=Sonus START (ATT OR LV3 OR MCI OR QST OR SPT OR VZB) | eval tg=case(match(Ingress_TG_Name,"^(ATT|LV3|MCI|QST|SPT|VZB)"),Ingress_TG_Name,match(Selected_TG_Name,"^(ATT|LV3|MCI|QST|SPT|VZB)"),Selected_TG_Name) | where NOT isnull(tg) | stats count by tg Site
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Is this possible using inputlookup or some other method?&lt;/P&gt;</description>
    <pubDate>Wed, 13 Feb 2013 22:44:54 GMT</pubDate>
    <dc:creator>tnkoehn</dc:creator>
    <dc:date>2013-02-13T22:44:54Z</dc:date>
    <item>
      <title>Use input file to create a search and use a match command</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Use-input-file-to-create-a-search-and-use-a-match-command/m-p/31613#M5557</link>
      <description>&lt;P&gt;I have a csv file with the following companies&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;ATT
LV3
MCI
QST
SPT
VZB
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Since the companies can change frequently, I would like to use that file to create a search that basically accomplishes the following&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=Sonus START (ATT OR LV3 OR MCI OR QST OR SPT OR VZB) | eval tg=case(match(Ingress_TG_Name,"^(ATT|LV3|MCI|QST|SPT|VZB)"),Ingress_TG_Name,match(Selected_TG_Name,"^(ATT|LV3|MCI|QST|SPT|VZB)"),Selected_TG_Name) | where NOT isnull(tg) | stats count by tg Site
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Is this possible using inputlookup or some other method?&lt;/P&gt;</description>
      <pubDate>Wed, 13 Feb 2013 22:44:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Use-input-file-to-create-a-search-and-use-a-match-command/m-p/31613#M5557</guid>
      <dc:creator>tnkoehn</dc:creator>
      <dc:date>2013-02-13T22:44:54Z</dc:date>
    </item>
    <item>
      <title>Re: Use input file to create a search and use a match command</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Use-input-file-to-create-a-search-and-use-a-match-command/m-p/31614#M5558</link>
      <description>&lt;P&gt;If you have a csv called companies.csv in var/run/splunk and the csv has a header of "Companies" like this &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Companies
ATT
LV3
MCI
QST
SPT
VZB
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;You can do this :&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=Sonus START [ | inputcsv companies 
                         | stats values(Companies) as Companies
                         | eval search=mvjoin(Companies," OR ")
                         | return $search
                       ] | ...
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This replaces [ ...  ] with ( ATT OR LV3 OR MCI etc etc )&lt;/P&gt;

&lt;P&gt;Its far simpler if the header in the CSV (in the example - "Companies") matches a field called "Companies" that is already extracted in the main search.&lt;/P&gt;

&lt;P&gt;Then you can just do :&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=Sonus START [ | inputcsv companies ] | ...
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;because the [ ... ] expands to :&lt;/P&gt;

&lt;P&gt;( ( Companies="ATT" ) OR ( Companies="LV3" ) OR ( Companies="MCI" ) etc )&lt;/P&gt;

&lt;P&gt;For the second part with the regex, you can do something similar :&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | eval regex=[ | inputcsv companies
                   | stats values(Companies) as Companies 
                   | eval search="\"^(".mvjoin(Companies,"|").")\"" 
                   | return $search
                 ] | ...
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;But ... this will murder performance, because the regex will be calculated for each row, so you could precalculate the values and map them in.&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Edit&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;
I tested this one with sample data. The problem is that you cant pass subqueries into map as a non-quoted string.&lt;BR /&gt;
I have a lookup table called procs.csv and it contains :&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;processors
nullqueue
header
previewout
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Working search :&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;* | head 1 
| eval regex=[ 
 | inputcsv procs
 | stats values(processors) as procs
 | eval search="\"^(".mvjoin(procs,"|").")\"" 
 | return $search ]
| map search="
  search index=_internal group=pipeline [
    | inputcsv procs
    | stats values(processors) as procs
    | eval procs= \"(\".mvjoin(procs,\" OR \").\")\"
    | return $procs ]
  | eval tg=case(match(processor,$regex$),processor,match(processor,$regex$),processor)
  | stats count by tg "
| table count tg
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 14 Feb 2013 01:10:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Use-input-file-to-create-a-search-and-use-a-match-command/m-p/31614#M5558</guid>
      <dc:creator>jonuwz</dc:creator>
      <dc:date>2013-02-14T01:10:40Z</dc:date>
    </item>
    <item>
      <title>Re: Use input file to create a search and use a match command</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Use-input-file-to-create-a-search-and-use-a-match-command/m-p/31615#M5559</link>
      <description>&lt;P&gt;This is excellent and it should work, but for some reason I'm getting 0 results. I know that $search_prefix$ and $regex$ are formatted correctly, but the search doesn't like them. For example, if I just replace $search_prefix$ with (ATT OR LV3 OR MCI OR QST OR SPT OR VZB) it works fine. Any ideas?&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 13:19:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Use-input-file-to-create-a-search-and-use-a-match-command/m-p/31615#M5559</guid>
      <dc:creator>tnkoehn</dc:creator>
      <dc:date>2020-09-28T13:19:16Z</dc:date>
    </item>
    <item>
      <title>Re: Use input file to create a search and use a match command</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Use-input-file-to-create-a-search-and-use-a-match-command/m-p/31616#M5560</link>
      <description>&lt;P&gt;the map search was inserting "(ATT OR LV3 OR MCI OR QST OR SPT OR VZB)" - i.e. it was quoted, and looking literally for that string - updated answer&lt;/P&gt;</description>
      <pubDate>Fri, 15 Feb 2013 13:06:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Use-input-file-to-create-a-search-and-use-a-match-command/m-p/31616#M5560</guid>
      <dc:creator>jonuwz</dc:creator>
      <dc:date>2013-02-15T13:06:03Z</dc:date>
    </item>
    <item>
      <title>Re: Use input file to create a search and use a match command</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Use-input-file-to-create-a-search-and-use-a-match-command/m-p/31617#M5561</link>
      <description>&lt;P&gt;Works perfectly! You are a genius! Thank you, thank you, thank you!&lt;/P&gt;</description>
      <pubDate>Fri, 15 Feb 2013 15:06:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Use-input-file-to-create-a-search-and-use-a-match-command/m-p/31617#M5561</guid>
      <dc:creator>tnkoehn</dc:creator>
      <dc:date>2013-02-15T15:06:31Z</dc:date>
    </item>
    <item>
      <title>Re: Use input file to create a search and use a match command</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Use-input-file-to-create-a-search-and-use-a-match-command/m-p/31618#M5562</link>
      <description>&lt;P&gt;one thing i would mention though. :&lt;/P&gt;

&lt;P&gt;This &lt;/P&gt;

&lt;P&gt;index=xxx (ABC OR DEF OR GHI)&lt;/P&gt;

&lt;P&gt;Will only return rows if ABC DEF GHI are complete words in the _raw message.&lt;/P&gt;

&lt;P&gt;words being strings surrounded by whitespace or punctuation.&lt;/P&gt;

&lt;P&gt;i.e. Company=ABCDEF  wont match&lt;/P&gt;</description>
      <pubDate>Fri, 15 Feb 2013 15:54:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Use-input-file-to-create-a-search-and-use-a-match-command/m-p/31618#M5562</guid>
      <dc:creator>jonuwz</dc:creator>
      <dc:date>2013-02-15T15:54:45Z</dc:date>
    </item>
    <item>
      <title>Re: Use input file to create a search and use a match command</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Use-input-file-to-create-a-search-and-use-a-match-command/m-p/31619#M5563</link>
      <description>&lt;P&gt;Really? That's strange because it is find things like ATT_0004_002, MCI_0323_005, etc. (which is exactly what I want it to do). Let me know if you think this is wrong.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 13:19:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Use-input-file-to-create-a-search-and-use-a-match-command/m-p/31619#M5563</guid>
      <dc:creator>tnkoehn</dc:creator>
      <dc:date>2020-09-28T13:19:40Z</dc:date>
    </item>
    <item>
      <title>Re: Use input file to create a search and use a match command</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Use-input-file-to-create-a-search-and-use-a-match-command/m-p/31620#M5564</link>
      <description>&lt;P&gt;Is it because there is an underscore?&lt;/P&gt;</description>
      <pubDate>Fri, 15 Feb 2013 16:00:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Use-input-file-to-create-a-search-and-use-a-match-command/m-p/31620#M5564</guid>
      <dc:creator>tnkoehn</dc:creator>
      <dc:date>2013-02-15T16:00:00Z</dc:date>
    </item>
    <item>
      <title>Re: Use input file to create a search and use a match command</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Use-input-file-to-create-a-search-and-use-a-match-command/m-p/31621#M5565</link>
      <description>&lt;P&gt;Yep - underscore is punctuation&lt;/P&gt;</description>
      <pubDate>Wed, 27 Feb 2013 23:30:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Use-input-file-to-create-a-search-and-use-a-match-command/m-p/31621#M5565</guid>
      <dc:creator>jonuwz</dc:creator>
      <dc:date>2013-02-27T23:30:49Z</dc:date>
    </item>
  </channel>
</rss>

