<?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: Using a subsearch to match a string and a field. in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Using-a-subsearch-to-match-a-string-and-a-field/m-p/116168#M30858</link>
    <description>&lt;P&gt;No need for a subsearch here. Setup the regex as automatic field extraction so you have the two fields available in the matching events &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.2.0/Knowledge/Managesearch-timefieldextractions"&gt;http://docs.splunk.com/Documentation/Splunk/6.2.0/Knowledge/Managesearch-timefieldextractions&lt;/A&gt;&lt;BR /&gt;
Check out this answer to get some ideas about how to compare fields &lt;A href="http://answers.splunk.com/answers/129424/how-to-compare-fields-over-multiple-sourcetypes-without-join-append-or-use-of-subsearches.html"&gt;http://answers.splunk.com/answers/129424/how-to-compare-fields-over-multiple-sourcetypes-without-join-append-or-use-of-subsearches.html&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;cheers, MuS&lt;/P&gt;</description>
    <pubDate>Thu, 13 Nov 2014 08:34:24 GMT</pubDate>
    <dc:creator>MuS</dc:creator>
    <dc:date>2014-11-13T08:34:24Z</dc:date>
    <item>
      <title>Using a subsearch to match a string and a field.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-a-subsearch-to-match-a-string-and-a-field/m-p/116165#M30855</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;In one of my indexes I've got a series of pipe separated fields which has one value expressed as so:&lt;/P&gt;

&lt;P&gt;31.22:88.91&lt;/P&gt;

&lt;P&gt;In other cases it's merely:&lt;/P&gt;

&lt;P&gt;88.91&lt;/P&gt;

&lt;P&gt;In order to match both occurrences of 88.91, I'm currently doing:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | rex field=foo ":(?&amp;lt;locx&amp;gt;\d+\.\d+)$" | rex field=_raw "|(?&amp;lt;locx&amp;gt;\d+\.\d+)|" ...
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This correctly extracts into "locx" cases where the raw data may appear as:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;John|Yellow|31.22:88.91|Thursday|Pass
Eve|Red|73.22:88.91|Monday|Pass
Mary|Green|88.91|Friday|Fail
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;But it will &lt;STRONG&gt;not&lt;/STRONG&gt; put into locx the following version:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Mark|Red|88.91:36.03|Monday|Pass
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The problem is what comes next - say the final field is "test_result" and I want to match all of the values of &lt;CODE&gt;locx&lt;/CODE&gt; where the test_result is pass, but then I want to find the events where the &lt;CODE&gt;locx&lt;/CODE&gt; from the test_result=pass is set, but &lt;STRONG&gt;only&lt;/STRONG&gt; when &lt;CODE&gt;locx&lt;/CODE&gt; is the second element in the colon separated version of the field, or when it's the only value (but never in the case of Mark where it's the FIRST value).&lt;/P&gt;

&lt;P&gt;What's the best way to do this?&lt;/P&gt;

&lt;P&gt;My thinking was that I'd do a subsearch for the pass conditions, get the value of locx for the Pass conditions, and the go back over the data and search for the fails; but that matches &lt;CODE&gt;locx&lt;/CODE&gt; in the case of Mark where 88.91 is the first of the two fields.&lt;/P&gt;

&lt;P&gt;I'm doing a horrific job of explaining this, but what I was looking for was the right way to say:&lt;/P&gt;

&lt;P&gt;"Match this condition in the data and then look for this field.  For each value of that field, go back through the data and find other matches for a different condition."&lt;/P&gt;

&lt;P&gt;From my pseudo data above, I'm trying to find people who failed an exam that took course 88.91 on its own, or, after taking some other course first.  But I don't want to find people who took course 88.91 and failed an exam if they took another course after 88.91.&lt;/P&gt;

&lt;P&gt;I need a drink.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 18:09:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-a-subsearch-to-match-a-string-and-a-field/m-p/116165#M30855</guid>
      <dc:creator>howyagoin</dc:creator>
      <dc:date>2020-09-28T18:09:12Z</dc:date>
    </item>
    <item>
      <title>Re: Using a subsearch to match a string and a field.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-a-subsearch-to-match-a-string-and-a-field/m-p/116166#M30856</link>
      <description>&lt;P&gt;Hi howyagoin,&lt;/P&gt;

&lt;P&gt;I would use two fields for this, using your provided data I would extract one field as &lt;CODE&gt;baseCourse&lt;/CODE&gt; (this would be 88.91 in your example) and &lt;CODE&gt;otherCourse&lt;/CODE&gt;  for the others. Try something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;.... | rex "[\:\|](?P&amp;lt;myCourse&amp;gt;\d+\.\d+)\|" | rex "\|(?P&amp;lt;otherCourse&amp;gt;\d+\.\d+)\:" | ....
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;this way you can compare the two field without any problem.&lt;/P&gt;

&lt;P&gt;hope this helps ...&lt;/P&gt;

&lt;P&gt;cheers, Mus&lt;/P&gt;</description>
      <pubDate>Wed, 12 Nov 2014 13:31:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-a-subsearch-to-match-a-string-and-a-field/m-p/116166#M30856</guid>
      <dc:creator>MuS</dc:creator>
      <dc:date>2014-11-12T13:31:43Z</dc:date>
    </item>
    <item>
      <title>Re: Using a subsearch to match a string and a field.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-a-subsearch-to-match-a-string-and-a-field/m-p/116167#M30857</link>
      <description>&lt;P&gt;Great approach MuS, thanks for that suggestion.  Do you have any recommendations on what the best comparison option would be, something using eval, perhaps?  &lt;/P&gt;

&lt;P&gt;I'm trying to ensure that after extracting &lt;CODE&gt;myCourse&lt;/CODE&gt; from the rex in a subsearch that when I go back to the main search I'm only matching those cases where &lt;CODE&gt;myCourse&lt;/CODE&gt; is not the same as &lt;CODE&gt;otherCourse&lt;/CODE&gt;.&lt;/P&gt;

&lt;P&gt;I think I'm just stuck at how to properly do the comparison check to make certain that the students who have a "failed" status for a given exam only have it if the only or most recent course they took was &lt;CODE&gt;myCourse&lt;/CODE&gt; and not if the only or most recent course they took was any &lt;CODE&gt;otherCourse&lt;/CODE&gt;.&lt;/P&gt;</description>
      <pubDate>Wed, 12 Nov 2014 19:55:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-a-subsearch-to-match-a-string-and-a-field/m-p/116167#M30857</guid>
      <dc:creator>howyagoin</dc:creator>
      <dc:date>2014-11-12T19:55:51Z</dc:date>
    </item>
    <item>
      <title>Re: Using a subsearch to match a string and a field.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-a-subsearch-to-match-a-string-and-a-field/m-p/116168#M30858</link>
      <description>&lt;P&gt;No need for a subsearch here. Setup the regex as automatic field extraction so you have the two fields available in the matching events &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.2.0/Knowledge/Managesearch-timefieldextractions"&gt;http://docs.splunk.com/Documentation/Splunk/6.2.0/Knowledge/Managesearch-timefieldextractions&lt;/A&gt;&lt;BR /&gt;
Check out this answer to get some ideas about how to compare fields &lt;A href="http://answers.splunk.com/answers/129424/how-to-compare-fields-over-multiple-sourcetypes-without-join-append-or-use-of-subsearches.html"&gt;http://answers.splunk.com/answers/129424/how-to-compare-fields-over-multiple-sourcetypes-without-join-append-or-use-of-subsearches.html&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;cheers, MuS&lt;/P&gt;</description>
      <pubDate>Thu, 13 Nov 2014 08:34:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-a-subsearch-to-match-a-string-and-a-field/m-p/116168#M30858</guid>
      <dc:creator>MuS</dc:creator>
      <dc:date>2014-11-13T08:34:24Z</dc:date>
    </item>
  </channel>
</rss>

