<?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: Trying to extract the value of a field which occurs twice in one event.  Regex maybe? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Trying-to-extract-the-value-of-a-field-which-occurs-twice-in-one/m-p/303236#M91232</link>
    <description>&lt;P&gt;Thanks Scott,&lt;/P&gt;

&lt;P&gt;I'm getting errors trying to add this to my search.  I think I'm missing something.&lt;BR /&gt;
Error in 'rex' command: Encountered the following error while compiling the regex 'Account Name:\s+(?\w+\$?)': Regex: unrecognized character after (? or (?-&lt;/P&gt;

&lt;P&gt;In your example is 'Account Name: a reference to my existing duplicate field, and Wanted_ID is a new name for the extracted field value?&lt;/P&gt;</description>
    <pubDate>Wed, 24 May 2017 14:47:34 GMT</pubDate>
    <dc:creator>rob_gibson</dc:creator>
    <dc:date>2017-05-24T14:47:34Z</dc:date>
    <item>
      <title>Trying to extract the value of a field which occurs twice in one event.  Regex maybe?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Trying-to-extract-the-value-of-a-field-which-occurs-twice-in-one/m-p/303234#M91230</link>
      <description>&lt;P&gt;I am hopeful someone has a suggestion for this reporting issue.&lt;/P&gt;

&lt;P&gt;I have an event generated by Microsoft SQL Audit, which is being written to the Windows:Security log on the forwarder.  I need to create a search string which captures the value of the 2nd "Account_Name" field, containing the value "userid".  However, "Account_Name" field appears twice in each record.  As the field name is not unique, my table is showing the value of both fields concatenated into one string.&lt;/P&gt;

&lt;P&gt;Source Data Sample;&lt;BR /&gt;
&lt;EM&gt;Subject:&lt;BR /&gt;
         Account Name: hostname1$&lt;BR /&gt;
New Logon: &lt;BR /&gt;
         Account Name: userid&lt;/EM&gt;&lt;/P&gt;

&lt;P&gt;Table results displayed for "Account_Name";&lt;BR /&gt;
hostname1$&lt;BR /&gt;
userid&lt;/P&gt;

&lt;P&gt;The following is sample event data (scrubbed);&lt;BR /&gt;
LogName=Security&lt;BR /&gt;
SourceName=Microsoft Windows security auditing.&lt;BR /&gt;
EventCode=4624&lt;BR /&gt;
EventType=0&lt;BR /&gt;
Type=Information&lt;BR /&gt;
ComputerName=hostname1.network.com&lt;BR /&gt;
TaskCategory=Logon&lt;BR /&gt;
OpCode=Info&lt;BR /&gt;
RecordNumber=559165&lt;BR /&gt;
Keywords=Audit Success&lt;BR /&gt;
Message=An account was successfully logged on.&lt;/P&gt;

&lt;P&gt;Subject:&lt;BR /&gt;
    Security ID:        S-1-5-18&lt;BR /&gt;
    Account Name:       hostname1$&lt;BR /&gt;
    Account Domain:     MyDomain&lt;BR /&gt;
    Logon ID:       0x3E7&lt;/P&gt;

&lt;P&gt;Logon Type:         10&lt;/P&gt;

&lt;P&gt;Impersonation Level:        Impersonation&lt;/P&gt;

&lt;P&gt;New Logon:&lt;BR /&gt;
    Security ID:        S-1-5-21-606747145-790525478-839522115-29674&lt;BR /&gt;
    Account Name:       userid&lt;BR /&gt;
    Account Domain:     MySubDomain&lt;BR /&gt;
    Logon ID:       0x16ABZ9093&lt;BR /&gt;
    Logon GUID:     {00000000-0000-0000-0000-000000000000}&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 14:08:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Trying-to-extract-the-value-of-a-field-which-occurs-twice-in-one/m-p/303234#M91230</guid>
      <dc:creator>rob_gibson</dc:creator>
      <dc:date>2020-09-29T14:08:23Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to extract the value of a field which occurs twice in one event.  Regex maybe?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Trying-to-extract-the-value-of-a-field-which-occurs-twice-in-one/m-p/303235#M91231</link>
      <description>&lt;P&gt;Rob,&lt;/P&gt;

&lt;P&gt;You can set a the query using the "rex" command and then mvindex using "eval".&lt;/P&gt;

&lt;P&gt;Something like this -&lt;/P&gt;

&lt;P&gt;| rex field=_raw max_match=5 "Account Name:\s+(?\w+\$?)" &lt;BR /&gt;
| eval Wanted_ID=mvindex(Account_Name,1) &lt;/P&gt;

&lt;P&gt;Note – The “1” in the mvindex returns the second instance of “Account Name”, count starts at 0.&lt;/P&gt;

&lt;P&gt;Hope this helps,&lt;/P&gt;

&lt;P&gt;Scott&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 14:08:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Trying-to-extract-the-value-of-a-field-which-occurs-twice-in-one/m-p/303235#M91231</guid>
      <dc:creator>scottrunyon</dc:creator>
      <dc:date>2020-09-29T14:08:31Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to extract the value of a field which occurs twice in one event.  Regex maybe?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Trying-to-extract-the-value-of-a-field-which-occurs-twice-in-one/m-p/303236#M91232</link>
      <description>&lt;P&gt;Thanks Scott,&lt;/P&gt;

&lt;P&gt;I'm getting errors trying to add this to my search.  I think I'm missing something.&lt;BR /&gt;
Error in 'rex' command: Encountered the following error while compiling the regex 'Account Name:\s+(?\w+\$?)': Regex: unrecognized character after (? or (?-&lt;/P&gt;

&lt;P&gt;In your example is 'Account Name: a reference to my existing duplicate field, and Wanted_ID is a new name for the extracted field value?&lt;/P&gt;</description>
      <pubDate>Wed, 24 May 2017 14:47:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Trying-to-extract-the-value-of-a-field-which-occurs-twice-in-one/m-p/303236#M91232</guid>
      <dc:creator>rob_gibson</dc:creator>
      <dc:date>2017-05-24T14:47:34Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to extract the value of a field which occurs twice in one event.  Regex maybe?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Trying-to-extract-the-value-of-a-field-which-occurs-twice-in-one/m-p/303237#M91233</link>
      <description>&lt;P&gt;Hey I got it to work!&lt;/P&gt;

&lt;P&gt;I left out the rex command and just used | eval Account_Name=mvindex(Account_Name,1) | in order to extract the second occurrence of the Account_Name field.&lt;/P&gt;

&lt;P&gt;Many thanks Scott!!&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 14:11:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Trying-to-extract-the-value-of-a-field-which-occurs-twice-in-one/m-p/303237#M91233</guid>
      <dc:creator>rob_gibson</dc:creator>
      <dc:date>2020-09-29T14:11:38Z</dc:date>
    </item>
  </channel>
</rss>

