<?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 extract a field in a search and table it with the timestamp of the event? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-a-field-in-a-search-and-table-it-with-the/m-p/162594#M46132</link>
    <description>&lt;P&gt;I'm assuming you have configured time extraction so you have  a proper time variable.  If so you can add the following onto your search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;your current search here&amp;gt; | rex "-\s+\[[^:]+:(?&amp;lt;firstname&amp;gt;[^_]+)_(?&amp;lt;lastname&amp;gt;\w+)@[^]]+\] - User authenticated$" | table _time firstname lastname
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.1.4/SearchReference/rex"&gt;rex&lt;/A&gt; command uses regular expressions to do the extraction of a first name and last name. (I'll talk more about the regex below).  &lt;/P&gt;

&lt;P&gt;We then take the output for the rex command and send it to the &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.1.4/SearchReference/table"&gt;table&lt;/A&gt; command so we can output the time, first name, and last name fields.&lt;/P&gt;

&lt;P&gt;Regular Expression&lt;/P&gt;

&lt;P&gt;If you view the regular expression in regex101 you can see an interactive explanation of what its doing (&lt;A href="http://regex101.com/r/nR1gK8/1"&gt;http://regex101.com/r/nR1gK8/1&lt;/A&gt;), but a quick rundown is below:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;-\s+\[[^:]+:(?&amp;lt;firstname&amp;gt;[^_]+)_(?&amp;lt;lastname&amp;gt;\w+)@[^]]+\] - User authenticated$
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;UL&gt;
&lt;LI&gt;The &lt;CODE&gt;-&lt;/CODE&gt; is a literal &lt;CODE&gt;-&lt;/CODE&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;CODE&gt;\s&lt;/CODE&gt; matches space characters and the &lt;CODE&gt;+&lt;/CODE&gt; means one or more&lt;/LI&gt;
&lt;LI&gt;&lt;CODE&gt;\[&lt;/CODE&gt; matches a literal &lt;CODE&gt;[&lt;/CODE&gt; character -- usually brackets mean to start a character class so the backslash &lt;CODE&gt;\&lt;/CODE&gt; is used to escape the opening bracket&lt;/LI&gt;
&lt;LI&gt;&lt;CODE&gt;[^:]+&lt;/CODE&gt; speaking of a character class, start a character class &lt;CODE&gt;[&lt;/CODE&gt; and &lt;CODE&gt;]&lt;/CODE&gt;, the &lt;CODE&gt;^&lt;/CODE&gt; in a character class means not, and the &lt;CODE&gt;:&lt;/CODE&gt; is a literal colon. So while complicated looking it says not a colon one or more times -- this should match sthisisencryptedpassword&lt;/LI&gt;
&lt;LI&gt;&lt;CODE&gt;:&lt;/CODE&gt; is a literal colon&lt;/LI&gt;
&lt;LI&gt;&lt;CODE&gt;(?...)&lt;/CODE&gt; - this is a capturing group so anything matched in the ... part will be saved in a field called first name&lt;/LI&gt;
&lt;LI&gt;&lt;CODE&gt;[^_]+&lt;/CODE&gt; is one or more characters that are not underscores&lt;/LI&gt;
&lt;LI&gt;&lt;CODE&gt;_&lt;/CODE&gt; is a literal underscore character&lt;/LI&gt;
&lt;LI&gt;&lt;CODE&gt;(?...)&lt;/CODE&gt; - another capturing group for last name&lt;/LI&gt;
&lt;LI&gt;&lt;CODE&gt;\w+&lt;/CODE&gt; is one or more word characters&lt;/LI&gt;
&lt;LI&gt;&lt;CODE&gt;@&lt;/CODE&gt; is a literal @&lt;/LI&gt;
&lt;LI&gt;&lt;CODE&gt;[^]]+&lt;/CODE&gt; is one or more characters that are not &lt;CODE&gt;]&lt;/CODE&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;CODE&gt;\]&lt;/CODE&gt; match a literal &lt;CODE&gt;]&lt;/CODE&gt; -- again like the opening bracket, usually brackets mean to start/end a character class, but we want a literal &lt;CODE&gt;]&lt;/CODE&gt; so we use a backslash &lt;CODE&gt;\&lt;/CODE&gt; to escape it &lt;/LI&gt;
&lt;LI&gt;&lt;CODE&gt;- User authenticated&lt;/CODE&gt; is just literally matching those characters&lt;/LI&gt;
&lt;LI&gt;&lt;CODE&gt;$&lt;/CODE&gt; is anchoring to the end of the line to try and make it more accurate &lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;Edited to break out the &lt;CODE&gt;\[&lt;/CODE&gt; as I incorrectly included it with the explanation below and I added a bit more explanation on the first character class.&lt;/P&gt;</description>
    <pubDate>Tue, 14 Oct 2014 14:33:12 GMT</pubDate>
    <dc:creator>triest</dc:creator>
    <dc:date>2014-10-14T14:33:12Z</dc:date>
    <item>
      <title>How to extract a field in a search and table it with the timestamp of the event?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-a-field-in-a-search-and-table-it-with-the/m-p/162593#M46131</link>
      <description>&lt;P&gt;Hi Experts,&lt;/P&gt;

&lt;P&gt;I'm getting below output in a PDF report from Splunk, &lt;/P&gt;

&lt;P&gt;2014-10-10 09:58:27 EDT (Framework:INFO) [RID:526] - [sthisisencryptedpassword:firstname_lastname@&lt;BR /&gt;
serial.mobile.com] - User authenticated&lt;/P&gt;

&lt;P&gt;I only need the report to contain,&lt;BR /&gt;
Time&lt;BR /&gt;
firstname_lastname&lt;/P&gt;

&lt;P&gt;Can I do this on Splunk or do I need to script on the log file before it is sent to Splunk. &lt;/P&gt;

&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Oct 2014 13:49:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-a-field-in-a-search-and-table-it-with-the/m-p/162593#M46131</guid>
      <dc:creator>kkossery</dc:creator>
      <dc:date>2014-10-14T13:49:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract a field in a search and table it with the timestamp of the event?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-a-field-in-a-search-and-table-it-with-the/m-p/162594#M46132</link>
      <description>&lt;P&gt;I'm assuming you have configured time extraction so you have  a proper time variable.  If so you can add the following onto your search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;your current search here&amp;gt; | rex "-\s+\[[^:]+:(?&amp;lt;firstname&amp;gt;[^_]+)_(?&amp;lt;lastname&amp;gt;\w+)@[^]]+\] - User authenticated$" | table _time firstname lastname
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.1.4/SearchReference/rex"&gt;rex&lt;/A&gt; command uses regular expressions to do the extraction of a first name and last name. (I'll talk more about the regex below).  &lt;/P&gt;

&lt;P&gt;We then take the output for the rex command and send it to the &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.1.4/SearchReference/table"&gt;table&lt;/A&gt; command so we can output the time, first name, and last name fields.&lt;/P&gt;

&lt;P&gt;Regular Expression&lt;/P&gt;

&lt;P&gt;If you view the regular expression in regex101 you can see an interactive explanation of what its doing (&lt;A href="http://regex101.com/r/nR1gK8/1"&gt;http://regex101.com/r/nR1gK8/1&lt;/A&gt;), but a quick rundown is below:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;-\s+\[[^:]+:(?&amp;lt;firstname&amp;gt;[^_]+)_(?&amp;lt;lastname&amp;gt;\w+)@[^]]+\] - User authenticated$
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;UL&gt;
&lt;LI&gt;The &lt;CODE&gt;-&lt;/CODE&gt; is a literal &lt;CODE&gt;-&lt;/CODE&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;CODE&gt;\s&lt;/CODE&gt; matches space characters and the &lt;CODE&gt;+&lt;/CODE&gt; means one or more&lt;/LI&gt;
&lt;LI&gt;&lt;CODE&gt;\[&lt;/CODE&gt; matches a literal &lt;CODE&gt;[&lt;/CODE&gt; character -- usually brackets mean to start a character class so the backslash &lt;CODE&gt;\&lt;/CODE&gt; is used to escape the opening bracket&lt;/LI&gt;
&lt;LI&gt;&lt;CODE&gt;[^:]+&lt;/CODE&gt; speaking of a character class, start a character class &lt;CODE&gt;[&lt;/CODE&gt; and &lt;CODE&gt;]&lt;/CODE&gt;, the &lt;CODE&gt;^&lt;/CODE&gt; in a character class means not, and the &lt;CODE&gt;:&lt;/CODE&gt; is a literal colon. So while complicated looking it says not a colon one or more times -- this should match sthisisencryptedpassword&lt;/LI&gt;
&lt;LI&gt;&lt;CODE&gt;:&lt;/CODE&gt; is a literal colon&lt;/LI&gt;
&lt;LI&gt;&lt;CODE&gt;(?...)&lt;/CODE&gt; - this is a capturing group so anything matched in the ... part will be saved in a field called first name&lt;/LI&gt;
&lt;LI&gt;&lt;CODE&gt;[^_]+&lt;/CODE&gt; is one or more characters that are not underscores&lt;/LI&gt;
&lt;LI&gt;&lt;CODE&gt;_&lt;/CODE&gt; is a literal underscore character&lt;/LI&gt;
&lt;LI&gt;&lt;CODE&gt;(?...)&lt;/CODE&gt; - another capturing group for last name&lt;/LI&gt;
&lt;LI&gt;&lt;CODE&gt;\w+&lt;/CODE&gt; is one or more word characters&lt;/LI&gt;
&lt;LI&gt;&lt;CODE&gt;@&lt;/CODE&gt; is a literal @&lt;/LI&gt;
&lt;LI&gt;&lt;CODE&gt;[^]]+&lt;/CODE&gt; is one or more characters that are not &lt;CODE&gt;]&lt;/CODE&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;CODE&gt;\]&lt;/CODE&gt; match a literal &lt;CODE&gt;]&lt;/CODE&gt; -- again like the opening bracket, usually brackets mean to start/end a character class, but we want a literal &lt;CODE&gt;]&lt;/CODE&gt; so we use a backslash &lt;CODE&gt;\&lt;/CODE&gt; to escape it &lt;/LI&gt;
&lt;LI&gt;&lt;CODE&gt;- User authenticated&lt;/CODE&gt; is just literally matching those characters&lt;/LI&gt;
&lt;LI&gt;&lt;CODE&gt;$&lt;/CODE&gt; is anchoring to the end of the line to try and make it more accurate &lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;Edited to break out the &lt;CODE&gt;\[&lt;/CODE&gt; as I incorrectly included it with the explanation below and I added a bit more explanation on the first character class.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Oct 2014 14:33:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-a-field-in-a-search-and-table-it-with-the/m-p/162594#M46132</guid>
      <dc:creator>triest</dc:creator>
      <dc:date>2014-10-14T14:33:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract a field in a search and table it with the timestamp of the event?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-a-field-in-a-search-and-table-it-with-the/m-p/162595#M46133</link>
      <description>&lt;P&gt;This is fantastic. Is there a manual where you can learn all of this? &lt;BR /&gt;
One more question - What if I want multiple users instead of firstname_lastname and some with only a firstname, without an underscore etc.. I tried to do a * in place of the firstname but it errors out.  &lt;/P&gt;</description>
      <pubDate>Tue, 14 Oct 2014 15:19:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-a-field-in-a-search-and-table-it-with-the/m-p/162595#M46133</guid>
      <dc:creator>kkossery</dc:creator>
      <dc:date>2014-10-14T15:19:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract a field in a search and table it with the timestamp of the event?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-a-field-in-a-search-and-table-it-with-the/m-p/162596#M46134</link>
      <description>&lt;P&gt;For Splunk search commands, if you click on the links for rex and table, there's really good online documentation about the various commands.&lt;/P&gt;

&lt;P&gt;For the regular expressions, there are lots of online tutorials.  Its really a matter of just copying and pasting and slowly learning.  Pre-college I did them a little bit and then in college I had a student position where I edited lots of Perl scripts.  The regex101 site is really helpful for testing regular expressions as it can really help you understand why its matching.&lt;/P&gt;

&lt;P&gt;I'm not sure what you mean by multiplier users, can you give an example?&lt;/P&gt;

&lt;P&gt;WARNING: I did not actually test this, but it should work (hopefully there aren't typo's)&lt;BR /&gt;
In terms of the "some with only a first name, without an underscore" you were on the right track to look at &lt;CODE&gt;*&lt;/CODE&gt;   The problem of changing &lt;CODE&gt;+&lt;/CODE&gt; to a &lt;CODE&gt;*&lt;/CODE&gt; is the &lt;CODE&gt;\w&lt;/CODE&gt; no longer must match a character, but you still have the &lt;CODE&gt;_&lt;/CODE&gt; listed so you would need an underscore to match.  The easiest way is to modify what I had is with put &lt;CODE&gt;(?: .... )?&lt;/CODE&gt; around &lt;CODE&gt;_(?\w+)&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;(?:...)&lt;/CODE&gt; - while the parenthesis make it look like a capturing group, the &lt;CODE&gt;?:&lt;/CODE&gt; make it a non-capturing group. The &lt;CODE&gt;?&lt;/CODE&gt; at the end makes it optional.  Thus we're saying the part inside the paren may or may not exist, match either way.  &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; -\s+\[[^:]+:(?&amp;lt;firstname&amp;gt;[^_]+)(?:_(?&amp;lt;lastname&amp;gt;\w+))?@[^]]+\] - User authenticated$
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 14 Oct 2014 15:47:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-a-field-in-a-search-and-table-it-with-the/m-p/162596#M46134</guid>
      <dc:creator>triest</dc:creator>
      <dc:date>2014-10-14T15:47:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract a field in a search and table it with the timestamp of the event?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-a-field-in-a-search-and-table-it-with-the/m-p/162597#M46135</link>
      <description>&lt;P&gt;Let's say my PDF output has the following,&lt;BR /&gt;
2014-10-10 09:58:27 EDT (Framework:INFO) [RID:526] - [randompassword123:bob.dole@&lt;BR /&gt;
politics.com] - User authenticated&lt;BR /&gt;
2014-10-10 09:59:31 EDT (Framework:INFO) [RID:526] - [sthisisencryptedpassword:tiger_woods@&lt;BR /&gt;
golf.com] - User authenticated&lt;BR /&gt;
2014-10-10 09:59:37 EDT (Framework:INFO) [RID:526] - [anotherpassword:roger@&lt;BR /&gt;
tennis.com] - User authenticated&lt;/P&gt;

&lt;P&gt;You can see the e-mail addresses are different. 1. has a period, 2. has an underscore and 3. doesn't have a lastname. &lt;/P&gt;</description>
      <pubDate>Tue, 14 Oct 2014 15:53:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-a-field-in-a-search-and-table-it-with-the/m-p/162597#M46135</guid>
      <dc:creator>kkossery</dc:creator>
      <dc:date>2014-10-14T15:53:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract a field in a search and table it with the timestamp of the event?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-a-field-in-a-search-and-table-it-with-the/m-p/162598#M46136</link>
      <description>&lt;P&gt;You can modify it to just use one field (I called it user) and you can use &lt;CODE&gt;[^@]&lt;/CODE&gt; to match any character except @ so that you can easily pick up things with &lt;CODE&gt;_&lt;/CODE&gt;, &lt;CODE&gt;-&lt;/CODE&gt; etc.&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;-\s+\[[^:]+:(?.*)@[^]]+\] - User authenticated&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Oct 2014 16:34:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-a-field-in-a-search-and-table-it-with-the/m-p/162598#M46136</guid>
      <dc:creator>triest</dc:creator>
      <dc:date>2014-10-14T16:34:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract a field in a search and table it with the timestamp of the event?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-a-field-in-a-search-and-table-it-with-the/m-p/162599#M46137</link>
      <description>&lt;P&gt;Hi Again - The requirement changed a bit and they need &lt;A href="mailto:firstname@emailaddress"&gt;firstname@emailaddress&lt;/A&gt;. I tried to define email like how we did for first name like this,&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;-\s+\[[^:]+:(?&amp;lt;firstname&amp;gt;[^@])+(?&amp;lt;email&amp;gt;)@[^]]+] - User authenticated | table _time firstname@email
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;However, splunk doesn't get it and only displays the last letter of the firstname. How can I include the firstname@email in the report.&lt;/P&gt;

&lt;P&gt;This is my &lt;STRONG&gt;working&lt;/STRONG&gt; expression. As you can see there is no lastname. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;rex "-\s+\[[^:]+:(?&amp;lt;firstname&amp;gt;[^@]+)@[^]]+] - User authenticated" | table _time firstname
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 15 Oct 2014 11:52:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-a-field-in-a-search-and-table-it-with-the/m-p/162599#M46137</guid>
      <dc:creator>kkossery</dc:creator>
      <dc:date>2014-10-15T11:52:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract a field in a search and table it with the timestamp of the event?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-a-field-in-a-search-and-table-it-with-the/m-p/162600#M46138</link>
      <description>&lt;P&gt;Finally got it,&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;-\s+\[[^:]+:(?&amp;lt;email&amp;gt;[^]]+)] - User authenticated
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 15 Oct 2014 13:27:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-a-field-in-a-search-and-table-it-with-the/m-p/162600#M46138</guid>
      <dc:creator>kkossery</dc:creator>
      <dc:date>2014-10-15T13:27:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract a field in a search and table it with the timestamp of the event?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-a-field-in-a-search-and-table-it-with-the/m-p/162601#M46139</link>
      <description>&lt;P&gt;Eventually this is what I wanted,&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;-\s+\[[^:]+:(?&amp;lt;email&amp;gt;[^]]+)] - User authenticated
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thank you triest!&lt;/P&gt;</description>
      <pubDate>Wed, 15 Oct 2014 13:28:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-a-field-in-a-search-and-table-it-with-the/m-p/162601#M46139</guid>
      <dc:creator>kkossery</dc:creator>
      <dc:date>2014-10-15T13:28:54Z</dc:date>
    </item>
  </channel>
</rss>

