<?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: How to use field inside quoted search as a variable? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-field-inside-quoted-search-as-a-variable/m-p/630089#M218894</link>
    <description>&lt;P&gt;Does this work for you?&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index="myIndex" source="mySource2"
    "User:myUserID The user is authenticated and logged in." 
    [search index="myIndex" 
    source="mySource1"
    | rex "Naam van gebruiker: (?&amp;lt;USER&amp;gt;.+) -"
    | dedup USER
    | table USER
    | sort USER
    | format] 
| stats latest(_raw) by USER&lt;/LI-CODE&gt;&lt;P&gt;Basically, use the search on mySource1 to find a list of USERs which you use to filter mySource2&lt;/P&gt;</description>
    <pubDate>Wed, 08 Feb 2023 12:13:38 GMT</pubDate>
    <dc:creator>ITWhisperer</dc:creator>
    <dc:date>2023-02-08T12:13:38Z</dc:date>
    <item>
      <title>How to use field inside quoted search as a variable?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-field-inside-quoted-search-as-a-variable/m-p/630085#M218891</link>
      <description>&lt;P&gt;Hi, I have the following joined Splunk query:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index="myIndex" 
source="mySource1"
| fields _time, _raw
| rex "Naam van gebruiker: (?&amp;lt;USER&amp;gt;.+) -"
| dedup USER
| table USER
| sort USER
| join type=left 
[ search
    index="myIndex"
    source="mySource2"
    "User:myUserID The user is authenticated and logged in." 
    | stats latest(_raw)
]&lt;/LI-CODE&gt;&lt;P&gt;The results look like this:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Bleepie_0-1675856259250.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/23776i0EB05AD922354545/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Bleepie_0-1675856259250.png" alt="Bleepie_0-1675856259250.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Bleepie_1-1675856264124.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/23777i00077C02002C95CE/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Bleepie_1-1675856264124.png" alt="Bleepie_1-1675856264124.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Green is myUserID. Red is some other persons user ID. Because I am using my hardcoded user ID, every person gets the "latest(_raw)" record corresponding to my user id. I want each user to get their own event. I believe this can be done if I use the USER field in the second search, but I don't know the syntax to get it to work. I tried:&lt;/P&gt;&lt;P&gt;"User:'USER' The user is authenticated and logged in."&lt;/P&gt;&lt;P&gt;And also&lt;/P&gt;&lt;P&gt;"User:\USER\ The user is authenticated and logged in."&lt;/P&gt;&lt;P&gt;But these don't work. What is the correct syntax?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Feb 2023 11:41:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-field-inside-quoted-search-as-a-variable/m-p/630085#M218891</guid>
      <dc:creator>Bleepie</dc:creator>
      <dc:date>2023-02-08T11:41:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to use field inside quoted search as a variable?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-field-inside-quoted-search-as-a-variable/m-p/630089#M218894</link>
      <description>&lt;P&gt;Does this work for you?&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index="myIndex" source="mySource2"
    "User:myUserID The user is authenticated and logged in." 
    [search index="myIndex" 
    source="mySource1"
    | rex "Naam van gebruiker: (?&amp;lt;USER&amp;gt;.+) -"
    | dedup USER
    | table USER
    | sort USER
    | format] 
| stats latest(_raw) by USER&lt;/LI-CODE&gt;&lt;P&gt;Basically, use the search on mySource1 to find a list of USERs which you use to filter mySource2&lt;/P&gt;</description>
      <pubDate>Wed, 08 Feb 2023 12:13:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-field-inside-quoted-search-as-a-variable/m-p/630089#M218894</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2023-02-08T12:13:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to use field inside quoted search as a variable?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-field-inside-quoted-search-as-a-variable/m-p/630092#M218896</link>
      <description>&lt;P&gt;Hi, this does not return any results. If I run the outher query and inner query both seperately, they work. But together Splunk replies "No results found. Try expanding the time range."&lt;/P&gt;&lt;P&gt;Also, in this query you still use a hardcoded user id.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Feb 2023 12:41:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-field-inside-quoted-search-as-a-variable/m-p/630092#M218896</guid>
      <dc:creator>Bleepie</dc:creator>
      <dc:date>2023-02-08T12:41:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to use field inside quoted search as a variable?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-field-inside-quoted-search-as-a-variable/m-p/630098#M218900</link>
      <description>&lt;P&gt;Maybe I need to clarify a bit:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Source 1 :&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;2023-02-01&lt;/SPAN&gt; &lt;SPAN class=""&gt;17:00:01&lt;/SPAN&gt; &lt;SPAN class=""&gt;-&lt;/SPAN&gt; &lt;SPAN class=""&gt;Naam&lt;/SPAN&gt; &lt;SPAN class=""&gt;van&lt;/SPAN&gt; &lt;SPAN class=""&gt;gebruiker:&lt;/SPAN&gt; &lt;SPAN class=""&gt;hank&lt;/SPAN&gt; &lt;SPAN class=""&gt;-&lt;/SPAN&gt; &lt;SPAN class=""&gt;Rol&lt;/SPAN&gt; &lt;SPAN class=""&gt;van&lt;/SPAN&gt; &lt;SPAN class=""&gt;gebruiker:&lt;/SPAN&gt; &lt;SPAN class=""&gt;operator&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;2023-02-02&lt;/SPAN&gt; &lt;SPAN class=""&gt;17:00:01&lt;/SPAN&gt; &lt;SPAN class=""&gt;-&lt;/SPAN&gt; &lt;SPAN class=""&gt;Naam&lt;/SPAN&gt; &lt;SPAN class=""&gt;van&lt;/SPAN&gt; &lt;SPAN class=""&gt;gebruiker:&lt;/SPAN&gt; &lt;SPAN class=""&gt;skylar&lt;/SPAN&gt; &lt;SPAN class=""&gt;-&lt;/SPAN&gt; &lt;SPAN class=""&gt;Rol&lt;/SPAN&gt; &lt;SPAN class=""&gt;van&lt;/SPAN&gt; &lt;SPAN class=""&gt;gebruiker:&lt;/SPAN&gt; &lt;SPAN class=""&gt;operator&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;2023-02-03 17:00:01 - Naam van gebruiker: walt - Rol van gebruiker: operator&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Source 2 :&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;2023-02-06 13:49:57,654 User:hank The user is authenticated and logged in.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;2023-02-07 13:49:57,654 User:skylar The user is authenticated and logged in.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;2023-02-08 13:49:57,654 User:walt The user is authenticated and logged in.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;2023-02-03 13:49:57,654 User:hank The user is authenticated and logged in.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;2023-02-02 13:49:57,654 User:skylar The user is authenticated and logged in.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;2023-02-01 13:49:57,654 User:walt The user is authenticated and logged in.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need a table. In that table I need a field called USER. USER is the name fetched from source 1. I also need a field called LATEST. In that field I want the entire row from source 2, but only the latest. So for example, I want the following output:&lt;BR /&gt;&lt;BR /&gt;USER, LATEST&lt;BR /&gt;hank,&amp;nbsp;&lt;SPAN&gt;2023-02-03 13:49:57,654 User:hank The user is authenticated and logged in.&lt;/SPAN&gt;&lt;BR /&gt;skylar,&amp;nbsp;&lt;SPAN&gt;2023-02-02 13:49:57,654 User:skylar The user is authenticated and logged in.&lt;/SPAN&gt;&lt;BR /&gt;walt,&amp;nbsp;&lt;SPAN&gt;2023-02-01 13:49:57,654 User:walt The user is authenticated and logged in.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Feb 2023 12:55:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-field-inside-quoted-search-as-a-variable/m-p/630098#M218900</guid>
      <dc:creator>Bleepie</dc:creator>
      <dc:date>2023-02-08T12:55:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to use field inside quoted search as a variable?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-field-inside-quoted-search-as-a-variable/m-p/630101#M218903</link>
      <description>&lt;P&gt;Have you already extracted USER from source2, or do you need to add a rex to do that too? (Your original post didn't include it, so I assumed it was already extracted.) Try something like this&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index="myIndex" source="mySource2"
    "The user is authenticated and logged in."
| rex "User:(?&amp;lt;USER&amp;gt;\w+) The user is authenticated and logged in."
| search [search index="myIndex" 
    source="mySource1"
    | rex "Naam van gebruiker: (?&amp;lt;USER&amp;gt;.+) -"
    | dedup USER
    | table USER
    | sort USER
    | format] 
| stats latest(_raw) by USER&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Feb 2023 13:09:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-field-inside-quoted-search-as-a-variable/m-p/630101#M218903</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2023-02-08T13:09:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to use field inside quoted search as a variable?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-field-inside-quoted-search-as-a-variable/m-p/630107#M218904</link>
      <description>&lt;P&gt;Yes, both sources need the user extracted. I tried to ran your latest query but no results show up.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried running it piece by piece:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index="myIndex"  source="mySource2"
    "The user is authenticated and logged in."
| rex "User:(?&amp;lt;USER&amp;gt;\w+) The user is authenticated and logged in."
| table USER
| dedup USER&lt;/LI-CODE&gt;&lt;P&gt;This will give me a list of users found within source 2. If I don't use the table and dedup I get all events instead.&lt;/P&gt;&lt;P&gt;If I run the other query:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index="myIndex" 
    source="mySource1"
    | rex "Naam van gebruiker: (?&amp;lt;USER&amp;gt;.+) -"
    | dedup USER
    | table USER
    | sort USER&lt;/LI-CODE&gt;&lt;P&gt;It returns a list of users found in the first source. Again, if I don't use dedup and table I get all the events.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Feb 2023 13:30:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-field-inside-quoted-search-as-a-variable/m-p/630107#M218904</guid>
      <dc:creator>Bleepie</dc:creator>
      <dc:date>2023-02-08T13:30:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to use field inside quoted search as a variable?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-field-inside-quoted-search-as-a-variable/m-p/630109#M218905</link>
      <description>&lt;P&gt;Not sure if I replied directly under you, check my response a few seconds ago.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Feb 2023 13:31:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-field-inside-quoted-search-as-a-variable/m-p/630109#M218905</guid>
      <dc:creator>Bleepie</dc:creator>
      <dc:date>2023-02-08T13:31:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to use field inside quoted search as a variable?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-field-inside-quoted-search-as-a-variable/m-p/630125#M218911</link>
      <description>&lt;P&gt;I have been playing and managed to get both sources like so:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index="myIndex"  source="mySource2"
    "The user is authenticated and logged in."
| rex "User:(?&amp;lt;USERLEFT&amp;gt;\w+) The user is authenticated and logged in."
| dedup USERLEFT
| append
 [search index="myIndex" 
    source="mySource2"
    | rex "Naam van gebruiker: (?&amp;lt;USERRIGHT&amp;gt;.+) -"
    | dedup USERRIGHT
]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can display both users from either source. The only thing I am missing now is how to build and compare both sources to get what I need.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Feb 2023 14:35:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-field-inside-quoted-search-as-a-variable/m-p/630125#M218911</guid>
      <dc:creator>Bleepie</dc:creator>
      <dc:date>2023-02-08T14:35:53Z</dc:date>
    </item>
  </channel>
</rss>

