<?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: Matching a field in a string using if/eval command. in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Matching-a-field-in-a-string-using-if-eval-command/m-p/684303#M233606</link>
    <description>&lt;P&gt;This is exactly what I am doing, nothing more.&amp;nbsp; Let me try your logic.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index= cloudaccount= cloudenv=impl source= (string in log a OR string in log b) | rex field=_raw "/[a-zA-Z0-9]+\/(?&amp;lt;filename&amp;gt;[^\"]*)"| rex field=_raw "[a-zA-Z0-9]+\/(?&amp;lt;filename2&amp;gt;[^\"]*)"
| eval Endtime = strftime(_time, "%H:%M:%S:%Q")
| eval Starttime = if(match(filename,"found %".filename2."%"),1,0)
| stats values(Starttime) by filename&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 15 Apr 2024 23:10:28 GMT</pubDate>
    <dc:creator>aotuga001</dc:creator>
    <dc:date>2024-04-15T23:10:28Z</dc:date>
    <item>
      <title>Matching a field in a string using if/eval command.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Matching-a-field-in-a-string-using-if-eval-command/m-p/684293#M233602</link>
      <description>&lt;P&gt;I have two logs below, log a is throughout the environment and would be shown for all users.&amp;nbsp; log b is limited to specific users.&amp;nbsp; I only need times for users in log b.&lt;/P&gt;
&lt;P&gt;log a:&amp;nbsp; There is a file has been received with the name test2.txt&lt;/P&gt;
&lt;P&gt;lob b:&amp;nbsp; The file has been found at the second destination C://user/test2.txt&lt;/P&gt;
&lt;P&gt;I am trying to write a query that captures the time between log a and log b without doing a subsearch, so far I have&amp;nbsp;&lt;/P&gt;
&lt;P&gt;index=a, env=a, account=a ("There is a file" OR "The file has been found")|field filename from log b | field filename2| eval Endtime = _time | ****&lt;STRONG&gt;Here is where I am lost, I was hoping to use if/match/like/eval to see to capture the start time where log b filename can be found in log a.&amp;nbsp; I have this so far******&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;| eval Starttime = if(match(filename,"There is%".filename2."%"),_time,0)&lt;/LI-CODE&gt;
&lt;P&gt;I am not getting any 1s, just 0s.&amp;nbsp; I am pretty sure this is the problem&amp;nbsp;&lt;STRONG&gt;"There is%".filename2."%",&amp;nbsp;&lt;/STRONG&gt;how do I correct it.&lt;/P&gt;</description>
      <pubDate>Mon, 15 Apr 2024 23:26:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Matching-a-field-in-a-string-using-if-eval-command/m-p/684293#M233602</guid>
      <dc:creator>aotuga001</dc:creator>
      <dc:date>2024-04-15T23:26:40Z</dc:date>
    </item>
    <item>
      <title>Re: Matching a field in a string using if/eval command.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Matching-a-field-in-a-string-using-if-eval-command/m-p/684296#M233603</link>
      <description>&lt;P&gt;Does logb come from "index=a env=a account="?&lt;/P&gt;&lt;P&gt;If not, then you need to search both data sets to find loga and logb.&lt;/P&gt;&lt;P&gt;I am not sure what your SPL&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;|field filename from log b | field filename2|&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;is doing, as that's not SPL.&lt;/P&gt;&lt;P&gt;your match statement is not valid either, you are using SQL wildcards (%) - match takes regular expressions.&lt;/P&gt;&lt;P&gt;Can you give an example of your data that you'd like to match&lt;/P&gt;</description>
      <pubDate>Mon, 15 Apr 2024 22:44:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Matching-a-field-in-a-string-using-if-eval-command/m-p/684296#M233603</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2024-04-15T22:44:56Z</dc:date>
    </item>
    <item>
      <title>Re: Matching a field in a string using if/eval command.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Matching-a-field-in-a-string-using-if-eval-command/m-p/684297#M233604</link>
      <description>&lt;UL&gt;&lt;LI&gt;Yes log b and log a have the same&amp;nbsp;&lt;SPAN&gt;index=a env=a account=.&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN&gt;SPL -----&amp;gt;&amp;nbsp;rex field=_raw "The file has been found at the second destination[a-zA-Z0-9]+\/(?&amp;lt;filename2&amp;gt;[^\"]*)"&amp;nbsp;&lt;STRONG&gt;This works I get the file names.&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN&gt;This is exactly the logs that I am trying to match, I was using if(like....) at first.&amp;nbsp;&lt;/SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;STRONG&gt;log a:&amp;nbsp; There is a file has been received with the name test2.txt&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;lob b:&amp;nbsp; The file has been found at the second destination C://user/test2.txt&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 15 Apr 2024 22:50:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Matching-a-field-in-a-string-using-if-eval-command/m-p/684297#M233604</guid>
      <dc:creator>aotuga001</dc:creator>
      <dc:date>2024-04-15T22:50:34Z</dc:date>
    </item>
    <item>
      <title>Re: Matching a field in a string using if/eval command.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Matching-a-field-in-a-string-using-if-eval-command/m-p/684300#M233605</link>
      <description>&lt;P&gt;If you have two events, you can't just match things between events - the text from loga does not exist when running the match statement for the logb data.&lt;/P&gt;&lt;P&gt;Without seeing your SPL it's hard to know what you are doing - can you post the entire SPL - please do this in a code block (&amp;lt;/&amp;gt; button)&lt;/P&gt;&lt;P&gt;If you have two events, you need to correlate them together using stats on a common field, in this case, your file name, so extract the file name from both events and then define a "message type" - log a or b and then you can do something like this logic&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval logtype=if(condition..., "loga", "logb")
| rex "....(?&amp;lt;filename&amp;gt;....)"
| stats count values(logtype) as logtypes min(_time) as StartTime max(_time) as EndTime by filename
| where count&amp;gt;1 AND logtypes="loga" AND logtypes="logb"&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 15 Apr 2024 22:59:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Matching-a-field-in-a-string-using-if-eval-command/m-p/684300#M233605</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2024-04-15T22:59:58Z</dc:date>
    </item>
    <item>
      <title>Re: Matching a field in a string using if/eval command.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Matching-a-field-in-a-string-using-if-eval-command/m-p/684303#M233606</link>
      <description>&lt;P&gt;This is exactly what I am doing, nothing more.&amp;nbsp; Let me try your logic.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index= cloudaccount= cloudenv=impl source= (string in log a OR string in log b) | rex field=_raw "/[a-zA-Z0-9]+\/(?&amp;lt;filename&amp;gt;[^\"]*)"| rex field=_raw "[a-zA-Z0-9]+\/(?&amp;lt;filename2&amp;gt;[^\"]*)"
| eval Endtime = strftime(_time, "%H:%M:%S:%Q")
| eval Starttime = if(match(filename,"found %".filename2."%"),1,0)
| stats values(Starttime) by filename&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 15 Apr 2024 23:10:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Matching-a-field-in-a-string-using-if-eval-command/m-p/684303#M233606</guid>
      <dc:creator>aotuga001</dc:creator>
      <dc:date>2024-04-15T23:10:28Z</dc:date>
    </item>
    <item>
      <title>Re: Matching a field in a string using if/eval command.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Matching-a-field-in-a-string-using-if-eval-command/m-p/684306#M233607</link>
      <description>&lt;P&gt;Great, thanks - that makes it easier!&lt;/P&gt;&lt;P&gt;OK, so it looks like you are trying to compare fields in two separate events - you can't do that unless you collapse the two.&lt;/P&gt;&lt;P&gt;You should use rex to extract a&amp;nbsp;&lt;STRONG&gt;single&lt;/STRONG&gt; filename and then do something similar to my previous post. Here's an example that hopefully will point you in the right direction.&lt;/P&gt;&lt;P&gt;It creates two events 60 seconds apart each containing a filename - the rex statements extract filename and logtype and the stats will join the events together and by using min and max on _time you can get the start and end times for the pair of events. The final where clause will ensure that you have seen both loga and logb events.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults
| eval v=split("log a:  There is a file has been received with the name test2.txt###log b:  The file has been found at the second destination C://user/test2.txt", "###")
| mvexpand v
| streamstats c
| eval _time=now()-(60*c)
| rename v as _raw
``` Above is simply a data set up example ```
| rex field=_raw "(/[a-zA-Z0-9]+\/|name )(?&amp;lt;filename&amp;gt;[^\"]*)"
| rex field=_raw "log (?&amp;lt;logtype&amp;gt;\w)"
| stats count min(_time) as Starttime max(_time) as Endtime values(logtype) as logtype by filename
| where count=2 AND logtype="a" AND logtype="b"
| eval diff = Endtime - Starttime&lt;/LI-CODE&gt;&lt;P&gt;Hope this helps.&lt;/P&gt;</description>
      <pubDate>Mon, 15 Apr 2024 23:24:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Matching-a-field-in-a-string-using-if-eval-command/m-p/684306#M233607</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2024-04-15T23:24:39Z</dc:date>
    </item>
    <item>
      <title>Re: Matching a field in a string using if/eval command.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Matching-a-field-in-a-string-using-if-eval-command/m-p/684453#M233654</link>
      <description>&lt;P&gt;It was perfect &lt;span class="lia-unicode-emoji" title=":beaming_face_with_smiling_eyes:"&gt;😁&lt;/span&gt;.&amp;nbsp; I ended up doing it like this because of how the logs are stored in our environment.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=c account=1  env=lower source="logfiles" ("destination" OR "received") | eval logtype = if(like(_raw, "destination%"),"logb","loga")
| rex field=_raw filename in loga| rex field=_raw filename in logb| stats count min(_time) as Starttime max(_time) as Endtime values(logtype) as logtype by filename
| where count=2 AND logtype="loga" AND logtype="logb"
| eval diff = Endtime - Starttime
| stats avg(diff)&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 17 Apr 2024 04:28:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Matching-a-field-in-a-string-using-if-eval-command/m-p/684453#M233654</guid>
      <dc:creator>aotuga001</dc:creator>
      <dc:date>2024-04-17T04:28:13Z</dc:date>
    </item>
  </channel>
</rss>

