<?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 Regex for field extraction in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Regex-for-field-extraction/m-p/189549#M54606</link>
    <description>&lt;P&gt;I am having a source file with the two below mentioned format. However I need to extract a same field but whose positions differ.&lt;BR /&gt;
Could anyone help me with appropriate regex?&lt;/P&gt;

&lt;P&gt;Jan 21 19:38:53 hostname sudo: pam_unix(sudo:session): session opened for user abc by xyz(uid=0)&lt;/P&gt;

&lt;P&gt;Jan 21 19:38:38 hostname sshd[000]: Accepted password for xyz from  port 123 &lt;/P&gt;

&lt;P&gt;Here I need to extract the user "xyz" . Both events belongs to same source. How could write the regex to match the both?&lt;/P&gt;

&lt;P&gt;OR do we need to go with Field alias?&lt;/P&gt;

&lt;P&gt;Thanks in advance&lt;/P&gt;</description>
    <pubDate>Thu, 22 Jan 2015 14:43:25 GMT</pubDate>
    <dc:creator>splunkn</dc:creator>
    <dc:date>2015-01-22T14:43:25Z</dc:date>
    <item>
      <title>Regex for field extraction</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-for-field-extraction/m-p/189549#M54606</link>
      <description>&lt;P&gt;I am having a source file with the two below mentioned format. However I need to extract a same field but whose positions differ.&lt;BR /&gt;
Could anyone help me with appropriate regex?&lt;/P&gt;

&lt;P&gt;Jan 21 19:38:53 hostname sudo: pam_unix(sudo:session): session opened for user abc by xyz(uid=0)&lt;/P&gt;

&lt;P&gt;Jan 21 19:38:38 hostname sshd[000]: Accepted password for xyz from  port 123 &lt;/P&gt;

&lt;P&gt;Here I need to extract the user "xyz" . Both events belongs to same source. How could write the regex to match the both?&lt;/P&gt;

&lt;P&gt;OR do we need to go with Field alias?&lt;/P&gt;

&lt;P&gt;Thanks in advance&lt;/P&gt;</description>
      <pubDate>Thu, 22 Jan 2015 14:43:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-for-field-extraction/m-p/189549#M54606</guid>
      <dc:creator>splunkn</dc:creator>
      <dc:date>2015-01-22T14:43:25Z</dc:date>
    </item>
    <item>
      <title>Re: Regex for field extraction</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-for-field-extraction/m-p/189550#M54607</link>
      <description>&lt;P&gt;One way is to extract both differently and then use coalesce function to grab the one that is not NULL&lt;/P&gt;

&lt;PRE&gt;
... |  rex "(?i)session opened for user \w+ by (?P&amp;lt;USER1&amp;gt;.\w+)\W"  |  rex "(?i)Accepted password for(?P&amp;lt;USER2&amp;gt;.\w+) from" 
    | eval USER = coalesce(USER1,USER2)
&lt;/PRE&gt;</description>
      <pubDate>Thu, 22 Jan 2015 15:33:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-for-field-extraction/m-p/189550#M54607</guid>
      <dc:creator>pradeepkumarg</dc:creator>
      <dc:date>2015-01-22T15:33:59Z</dc:date>
    </item>
  </channel>
</rss>

