<?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 Search pattern from one file in another file in same time frame in Splunk Enterprise</title>
    <link>https://community.splunk.com/t5/Splunk-Enterprise/Search-pattern-from-one-file-in-another-file-in-same-time-frame/m-p/330683#M7222</link>
    <description>&lt;P&gt;Hello,&lt;BR /&gt;
I have a pattern in one file that I need to check if it has occurred in another file. The two files are like:&lt;BR /&gt;
file1:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;aaa bbb ccc STRING I NEED 1 ddd some random text
aaa bbb ccc STRING I NEED 2 ddd some random text
aaa bbb ccc STRING I NEED 3 ddd some random text
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;file 2:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;www xxx  PATTERN FROM FILE 1 yyy zzz
www xxx  PATTERN FROM FILE 1 yyy zzz
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I tried something like this but doesn't return anything&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;source="file2" [search source="file1" "aaa bbb ccc" | rex  "aaa bbb ccc  (?&amp;lt;extraction_name&amp;gt;.*) ddd"]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;though I admit I don't fully understand the above query. Help would be appreciated, thanks.&lt;/P&gt;</description>
    <pubDate>Tue, 12 Sep 2017 13:07:54 GMT</pubDate>
    <dc:creator>Vettori</dc:creator>
    <dc:date>2017-09-12T13:07:54Z</dc:date>
    <item>
      <title>Search pattern from one file in another file in same time frame</title>
      <link>https://community.splunk.com/t5/Splunk-Enterprise/Search-pattern-from-one-file-in-another-file-in-same-time-frame/m-p/330683#M7222</link>
      <description>&lt;P&gt;Hello,&lt;BR /&gt;
I have a pattern in one file that I need to check if it has occurred in another file. The two files are like:&lt;BR /&gt;
file1:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;aaa bbb ccc STRING I NEED 1 ddd some random text
aaa bbb ccc STRING I NEED 2 ddd some random text
aaa bbb ccc STRING I NEED 3 ddd some random text
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;file 2:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;www xxx  PATTERN FROM FILE 1 yyy zzz
www xxx  PATTERN FROM FILE 1 yyy zzz
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I tried something like this but doesn't return anything&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;source="file2" [search source="file1" "aaa bbb ccc" | rex  "aaa bbb ccc  (?&amp;lt;extraction_name&amp;gt;.*) ddd"]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;though I admit I don't fully understand the above query. Help would be appreciated, thanks.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Sep 2017 13:07:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Enterprise/Search-pattern-from-one-file-in-another-file-in-same-time-frame/m-p/330683#M7222</guid>
      <dc:creator>Vettori</dc:creator>
      <dc:date>2017-09-12T13:07:54Z</dc:date>
    </item>
    <item>
      <title>Re: Search pattern from one file in another file in same time frame</title>
      <link>https://community.splunk.com/t5/Splunk-Enterprise/Search-pattern-from-one-file-in-another-file-in-same-time-frame/m-p/330684#M7223</link>
      <description>&lt;P&gt;Just like in math you start with parentheses, in SPL you start with square brackets (subsearch).  The subsearch in this case is looking for the "STRING I NEED" in source file 1.  The results of the subsearch then become part of the main search as in "source=file2 STRING I NEED".  Your query seems nearly there.  Try adding a &lt;CODE&gt;return&lt;/CODE&gt; statement to the subsearch.  Like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;source="file2" [search source="file1" "aaa bbb ccc" | rex  "aaa bbb ccc  (?&amp;lt;extraction_name&amp;gt;.*) ddd" | return extraction_name]
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 12 Sep 2017 13:27:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Enterprise/Search-pattern-from-one-file-in-another-file-in-same-time-frame/m-p/330684#M7223</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2017-09-12T13:27:51Z</dc:date>
    </item>
    <item>
      <title>Re: Search pattern from one file in another file in same time frame</title>
      <link>https://community.splunk.com/t5/Splunk-Enterprise/Search-pattern-from-one-file-in-another-file-in-same-time-frame/m-p/330685#M7224</link>
      <description>&lt;P&gt;Hi Vettori,&lt;BR /&gt;
some additional information:&lt;BR /&gt;
in File 1, do you have a list of patterns and each event is the pattern to search in File 2 or does each event contain patterns to search in File 2?&lt;BR /&gt;
anyway if each event of file 1 is exactly the pattern to search (as you use brackets) you could use something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;search_on_File2 [ search search_on_File1 | rename _raw AS query | fields query ]
| ...
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;if instead pattern is like the example you shared "aaa bbb ccc STRING I NEED 1 ddd some random text", you have to extract pattern from the search in File1 (e.g. using a regex like the following &lt;CODE&gt;^(?&amp;lt;pattern&amp;gt;.*)\sSTRING I NEED&lt;/CODE&gt;)&lt;BR /&gt;
so try something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;search_on_File2 [ search search_on_File1 | rex "^(?&amp;lt;pattern&amp;gt;.*)\sSTRING I NEED" | rename pattern AS query | fields query ]
| ...
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Bye.&lt;BR /&gt;
Giuseppe&lt;/P&gt;</description>
      <pubDate>Tue, 12 Sep 2017 13:34:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Enterprise/Search-pattern-from-one-file-in-another-file-in-same-time-frame/m-p/330685#M7224</guid>
      <dc:creator>gcusello</dc:creator>
      <dc:date>2017-09-12T13:34:10Z</dc:date>
    </item>
    <item>
      <title>Re: Search pattern from one file in another file in same time frame</title>
      <link>https://community.splunk.com/t5/Splunk-Enterprise/Search-pattern-from-one-file-in-another-file-in-same-time-frame/m-p/330686#M7225</link>
      <description>&lt;P&gt;I tried the above query but still did not return any results. However using format directive seems to work.&lt;BR /&gt;
So now my query is like: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; source="file2" [search source="file1" "aaa bbb ccc" | rex  "aaa bbb ccc  (?&amp;lt;extraction_name&amp;gt;.*) ddd" | stats count by extraction_name | fields + extraction_name | format | eval search =replace(search, "extraction_name=", "")]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I ran the subquery alone from above and saw that the results returned were like so:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;((STRING I NEED 1) OR (STRING I NEED 3) OR (STRING I NEED 3))
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;which is exactly what I need to be searched in the outer query.&lt;/P&gt;

&lt;P&gt;In the query mentioned in the question, the intention was that the subquery would return something along:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;("STRING I NEED 1" "STRING I NEED 2" "STRING I NEED 3")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;It turned out it didn't so, I don't understand why.&lt;/P&gt;

&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Sep 2017 07:53:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Enterprise/Search-pattern-from-one-file-in-another-file-in-same-time-frame/m-p/330686#M7225</guid>
      <dc:creator>Vettori</dc:creator>
      <dc:date>2017-09-13T07:53:08Z</dc:date>
    </item>
    <item>
      <title>Re: Search pattern from one file in another file in same time frame</title>
      <link>https://community.splunk.com/t5/Splunk-Enterprise/Search-pattern-from-one-file-in-another-file-in-same-time-frame/m-p/330687#M7226</link>
      <description>&lt;P&gt;My case is the latter one. Seems solved now though. Thanks.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Sep 2017 07:56:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Enterprise/Search-pattern-from-one-file-in-another-file-in-same-time-frame/m-p/330687#M7226</guid>
      <dc:creator>Vettori</dc:creator>
      <dc:date>2017-09-13T07:56:33Z</dc:date>
    </item>
    <item>
      <title>Re: Search pattern from one file in another file in same time frame</title>
      <link>https://community.splunk.com/t5/Splunk-Enterprise/Search-pattern-from-one-file-in-another-file-in-same-time-frame/m-p/330688#M7227</link>
      <description>&lt;P&gt;The &lt;CODE&gt;OR&lt;/CODE&gt; keywords are significant.  Without them, &lt;CODE&gt;AND&lt;/CODE&gt; is implied and won't work since no event has all of the strings you need.  Good on you for discovering &lt;CODE&gt;format&lt;/CODE&gt;.&lt;BR /&gt;
If your problem is resolved, please accept an answer to help future readers.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Sep 2017 12:52:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Enterprise/Search-pattern-from-one-file-in-another-file-in-same-time-frame/m-p/330688#M7227</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2017-09-13T12:52:51Z</dc:date>
    </item>
  </channel>
</rss>

