<?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: rex command by comparing two different indexes in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-rex-command-by-comparing-two-different-indexes/m-p/645945#M223631</link>
    <description>&lt;P&gt;hi sir, thanks for your reply.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to extract the field userName from indexA, which starts with user (i.e. firstname)&lt;/P&gt;&lt;P&gt;so, i have to extract from _raw.&amp;nbsp;&lt;/P&gt;&lt;P&gt;userName field is already available in indexB and giving the same name for newly extracted field&lt;/P&gt;&lt;P&gt;Also, i tried using rex command separately and the result is as expected&lt;/P&gt;&lt;P&gt;index=indexA sourcetype="A" user=*&lt;BR /&gt;| rex field=_raw "user=(?&amp;lt;userName&amp;gt;[^.]*)\s+cat"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 06 Jun 2023 15:08:52 GMT</pubDate>
    <dc:creator>RanjiRaje</dc:creator>
    <dc:date>2023-06-06T15:08:52Z</dc:date>
    <item>
      <title>How to write rex command by comparing two different indexes?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-rex-command-by-comparing-two-different-indexes/m-p/645932#M223629</link>
      <description>&lt;P&gt;Hi all, I need your help in validating my query. Please help..&lt;/P&gt;
&lt;P&gt;in indexA , fields are: user, login&lt;BR /&gt;(user=firstname, login=login_id)&lt;BR /&gt;in indexB , fields are: userName, city&lt;BR /&gt;(city: location of the employee, userName:firstname comma lastname)&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;I have userName in indexA but it was not extracted under any field name. So I am extracting this field and based on that userName combination, I need to get location of that employee.&lt;BR /&gt;I am trying with the below query, but it is not giving location detail. Location is emplty for all rows&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;(index=indexA sourcetype="A" user=*) OR (index=indexB sourcetype="B" userName=*)
| rex field=_raw "user=(?&amp;lt;userName&amp;gt;[^.]*)\s+cat"
| fields userName city login
| stats count as events values(city) as city by userName login&lt;/LI-CODE&gt;
&lt;P&gt;eg:user=aaa, login=aabb&lt;BR /&gt;city=xyz, userName=aaa, bbb&lt;/P&gt;
&lt;P&gt;with my query I have to get result as&lt;/P&gt;
&lt;TABLE width="261"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="69"&gt;userName&lt;/TD&gt;
&lt;TD width="64"&gt;login&lt;/TD&gt;
&lt;TD width="64"&gt;events&lt;/TD&gt;
&lt;TD width="64"&gt;city&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;aaa, bbb&lt;/TD&gt;
&lt;TD&gt;aabb&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;xyz&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;But Iam getting empty in city. please help.. Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 06 Jun 2023 14:36:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-rex-command-by-comparing-two-different-indexes/m-p/645932#M223629</guid>
      <dc:creator>RanjiRaje</dc:creator>
      <dc:date>2023-06-06T14:36:19Z</dc:date>
    </item>
    <item>
      <title>Re: rex command by comparing two different indexes</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-rex-command-by-comparing-two-different-indexes/m-p/645933#M223630</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/254020"&gt;@RanjiRaje&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;please try this regex:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| rex field=userName "^(?&amp;lt;user&amp;gt;[^,]*)"&lt;/LI-CODE&gt;&lt;P&gt;that you can test at&amp;nbsp;&lt;A href="https://regex101.com/r/NcAZbu/1" target="_blank"&gt;https://regex101.com/r/NcAZbu/1&lt;/A&gt;&lt;/P&gt;&lt;P&gt;so you could try something like this:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;(index=indexA sourcetype="A" user=*) OR (index=indexB sourcetype="B" userName=*)
| rex field=userName "^(?&amp;lt;user&amp;gt;[^,]*)"
| stats 
   count AS events 
   values(city) AS city 
   values(login) AS login 
   BY user&lt;/LI-CODE&gt;&lt;P&gt;Ciao.&lt;/P&gt;&lt;P&gt;Giuseppe&lt;/P&gt;</description>
      <pubDate>Tue, 06 Jun 2023 14:36:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-rex-command-by-comparing-two-different-indexes/m-p/645933#M223630</guid>
      <dc:creator>gcusello</dc:creator>
      <dc:date>2023-06-06T14:36:40Z</dc:date>
    </item>
    <item>
      <title>Re: rex command by comparing two different indexes</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-rex-command-by-comparing-two-different-indexes/m-p/645945#M223631</link>
      <description>&lt;P&gt;hi sir, thanks for your reply.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to extract the field userName from indexA, which starts with user (i.e. firstname)&lt;/P&gt;&lt;P&gt;so, i have to extract from _raw.&amp;nbsp;&lt;/P&gt;&lt;P&gt;userName field is already available in indexB and giving the same name for newly extracted field&lt;/P&gt;&lt;P&gt;Also, i tried using rex command separately and the result is as expected&lt;/P&gt;&lt;P&gt;index=indexA sourcetype="A" user=*&lt;BR /&gt;| rex field=_raw "user=(?&amp;lt;userName&amp;gt;[^.]*)\s+cat"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Jun 2023 15:08:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-rex-command-by-comparing-two-different-indexes/m-p/645945#M223631</guid>
      <dc:creator>RanjiRaje</dc:creator>
      <dc:date>2023-06-06T15:08:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to write rex command by comparing two different indexes?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-rex-command-by-comparing-two-different-indexes/m-p/645982#M223639</link>
      <description>&lt;P&gt;Either the problem is ill-defined or there's some key characteristics missing from your description.&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;in indexA , fields are: user, login&lt;BR /&gt;(user=firstname, login=login_id)&lt;BR /&gt;in indexB , fields are: userName, city&lt;BR /&gt;(city: location of the employee, userName:firstname comma lastname)&lt;P&gt;&lt;BR /&gt;I have userName in indexA but it was not extracted under any field name. So I am extracting this field and based on that userName combination, I need to get location of that employee.&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| rex field=_raw "user=(?&amp;lt;userName&amp;gt;[^.]*)\s+cat"&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;HR /&gt;&lt;P&gt;You first stated that a field "user" exists in indexA that only gives you only first name. &amp;nbsp;Obviously the field "user" cannot be used to match userName in indexB. &amp;nbsp;Then, in the rex, you are trying to extract a full name that is in the same format as being used in indexB, namely "userName:firstname comma lastname", by looking after prefix "user=" for any string that doe not contain a dot (".") and preceding a pattern matching any blank followed by string "cat". &amp;nbsp;If this rex would extract a pattern like "userName:firstname comma lastname", I don't see why Splunk would not have already populated field "user" with the same pattern. &amp;nbsp;Can you illustrate raw data to see what is being extracted by that rex in both indexA and indexB? (But especially in indexA.) &amp;nbsp;You can use this as an alternative test so we don't risk overriding existing value in indexB&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| rex field=_raw "user=(?&amp;lt;AuserName&amp;gt;[^.]*)\s+cat"&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also, can you confirm that "city" is fully populated in indexB?&lt;/P&gt;</description>
      <pubDate>Tue, 06 Jun 2023 17:18:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-rex-command-by-comparing-two-different-indexes/m-p/645982#M223639</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2023-06-06T17:18:42Z</dc:date>
    </item>
    <item>
      <title>Re: rex command by comparing two different indexes</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-rex-command-by-comparing-two-different-indexes/m-p/646029#M223649</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/254020"&gt;@RanjiRaje&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;I cannot test your regex because you didn't share your raw events.&lt;/P&gt;&lt;P&gt;Anyway, you said that in indexA you have user=firstname and in indexB you have userName=firstname,login.&lt;/P&gt;&lt;P&gt;You already have the user field from indexA and using my regex you can extract the firstname from the userName field of the indexB and can you use it for matching with indexA.&lt;/P&gt;&lt;P&gt;Isn't this your requirement?&lt;/P&gt;&lt;P&gt;if you want, you can also rename user as userName at the end of the search.&lt;/P&gt;&lt;P&gt;I could be more detailed, if you could share a sample of your raw logs from indexA and indexB.&lt;/P&gt;&lt;P&gt;Ciao.&lt;/P&gt;&lt;P&gt;Giuseppe&lt;/P&gt;</description>
      <pubDate>Wed, 07 Jun 2023 07:17:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-rex-command-by-comparing-two-different-indexes/m-p/646029#M223649</guid>
      <dc:creator>gcusello</dc:creator>
      <dc:date>2023-06-07T07:17:28Z</dc:date>
    </item>
  </channel>
</rss>

