<?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 create a field with varying lengths of field values? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-field-with-varying-lengths-of-field-values/m-p/355626#M170126</link>
    <description>&lt;P&gt;Here it is a working complete example with the extraction of "field1"&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults count=2
| streamstats count
| eval _raw=case(count==1,"&amp;lt;37&amp;gt; 1 2018-04-23T08:08:08Z E876876876 SECURE AUDIT 0 &amp;lt;secure audit error&amp;gt; [cdkncdckne dckmdkcmd]",count==2,"&amp;lt;37&amp;gt; 1 2018-04-23T08:08:08Z E876876876 auth 0 &amp;lt;login&amp;gt; [kdnckn rrgrr]
&amp;lt;37&amp;gt; 1 2018-04-23T08:08:08Z E876876876 auth 0 &amp;lt;login&amp;gt; [kdnckn rrgrr]")
| rex field=_raw "&amp;lt;\d+&amp;gt;\s+\d+\s+(?:[^\s]+\s){2}(?P&amp;lt;field1&amp;gt;[^\s]+(?:\s+\w+)*)\s\d+\s+&amp;lt;"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/4812i1F0141C5E148A477/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 24 Apr 2018 12:38:23 GMT</pubDate>
    <dc:creator>cafissimo</dc:creator>
    <dc:date>2018-04-24T12:38:23Z</dc:date>
    <item>
      <title>How to create a field with varying lengths of field values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-field-with-varying-lengths-of-field-values/m-p/355615#M170115</link>
      <description>&lt;P&gt;I want to create a field which extract values, however I have some field values that I want to extract which contain more than one word. &lt;BR /&gt;
For instance:&lt;BR /&gt;
&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/4813i12F62D5D682DA63D/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt; (image file: field-error.png)&lt;/P&gt;

&lt;P&gt;I want the 'auth' and 'SECURE AUDIT' values to be considered as part of the same field that I am going to create. However I got the field extraction error message: "The extraction failed. If you are extracting multiple fields, try removing one or more fields. Start with extractions that are embedded within longer text strings."&lt;/P&gt;

&lt;P&gt;Basically I want to extract the text between the yellow boxed text and the value '0' to be added as a field. &lt;BR /&gt;
How can I add the field such that I don't get the error?&lt;/P&gt;

&lt;P&gt;Splunk only highlighted the first word 'SECURE' instead of 'SECURE AUDIT', which is not what I want. &lt;/P&gt;

&lt;P&gt;Output with the following regex suggested:&lt;/P&gt;

&lt;P&gt;(?:[^\s]+\s){2}(?P[^\s]+(?:\s\w+)?)\s\d+\s+&amp;lt;&lt;/P&gt;

&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/4814iB990DD2F2B9AFC2C/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt; (image file: error-3.png)&lt;/P&gt;

&lt;P&gt;I tried to modify the regex by removing the 'w', and it highlighted only the 'auth' texts and 'AUDIT' without the 'SECURE'&lt;/P&gt;

&lt;P&gt;To display the result output I have removed my second image as Splunk only allows two image files uploaded. &lt;/P&gt;

&lt;P&gt;Regular expression generated by Splunk:&lt;BR /&gt;
^(?:[^ \n]* ){3}(?P\w+\s+\w+)&lt;/P&gt;

&lt;P&gt;I realized the regex suggested by one user extracted wrongly as he/she did not include &amp;lt; 37 &amp;gt; 1 at the front of the lines as indicated in my text line. The wording got misaligned and hence the wrong extraction. &lt;BR /&gt;
&lt;A href="https://regex101.com/r/biHi9a/4"&gt;https://regex101.com/r/biHi9a/4&lt;/A&gt; &lt;BR /&gt;
The link above is the correct sample text that I want to work with. Would appreciate any help to modify it to achieve my desired results. &lt;/P&gt;</description>
      <pubDate>Mon, 23 Apr 2018 09:55:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-field-with-varying-lengths-of-field-values/m-p/355615#M170115</guid>
      <dc:creator>gilbxrtx_7</dc:creator>
      <dc:date>2018-04-23T09:55:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a field with varying lengths of field values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-field-with-varying-lengths-of-field-values/m-p/355616#M170116</link>
      <description>&lt;P&gt;Can you share the regular expression that Splunk generates for you? Then we can help adjust it to achieve your desired result.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Apr 2018 13:39:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-field-with-varying-lengths-of-field-values/m-p/355616#M170116</guid>
      <dc:creator>FrankVl</dc:creator>
      <dc:date>2018-04-23T13:39:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a field with varying lengths of field values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-field-with-varying-lengths-of-field-values/m-p/355617#M170117</link>
      <description>&lt;P&gt;Try this regex &lt;/P&gt;

&lt;P&gt;rex field = _raw "\s+\w+\s+(?P.*)\s+\d+"&lt;/P&gt;</description>
      <pubDate>Mon, 23 Apr 2018 14:14:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-field-with-varying-lengths-of-field-values/m-p/355617#M170117</guid>
      <dc:creator>ssadanala1</dc:creator>
      <dc:date>2018-04-23T14:14:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a field with varying lengths of field values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-field-with-varying-lengths-of-field-values/m-p/355618#M170118</link>
      <description>&lt;P&gt;Can you try:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rex field=_raw "(?P&amp;lt;field1&amp;gt;[^\s]+)\s\d+\&amp;lt;"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 23 Apr 2018 14:18:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-field-with-varying-lengths-of-field-values/m-p/355618#M170118</guid>
      <dc:creator>p_gurav</dc:creator>
      <dc:date>2018-04-23T14:18:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a field with varying lengths of field values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-field-with-varying-lengths-of-field-values/m-p/355619#M170119</link>
      <description>&lt;P&gt;Try this regex:&lt;/P&gt;

&lt;BLOCKQUOTE&gt;
&lt;P&gt;(?:[^\s]+\s){2}(?P[^\s]+(?:\s\w+)?)\s\d+\s+&amp;lt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;

&lt;P&gt;Test it here:&lt;BR /&gt;
&lt;A href="https://regex101.com/r/biHi9a/1"&gt;https://regex101.com/r/biHi9a/1&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Best regards&lt;/P&gt;</description>
      <pubDate>Mon, 23 Apr 2018 14:38:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-field-with-varying-lengths-of-field-values/m-p/355619#M170119</guid>
      <dc:creator>cafissimo</dc:creator>
      <dc:date>2018-04-23T14:38:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a field with varying lengths of field values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-field-with-varying-lengths-of-field-values/m-p/355620#M170120</link>
      <description>&lt;P&gt;Hi, your answer seems correct in the regex test link. However when I copied and paste the exact regex into splunk, it somehow highlighted the text wrongly.&lt;/P&gt;

&lt;P&gt;It highlighted the text before the auth as part of the field extraction as well.&lt;/P&gt;

&lt;P&gt;I have edited my question to display the output when I added the regex you suggested into splunk. &lt;BR /&gt;
@cafissimo&lt;/P&gt;

&lt;P&gt;&lt;A href="https://regex101.com/r/biHi9a/4"&gt;https://regex101.com/r/biHi9a/4&lt;/A&gt; &lt;BR /&gt;
I realized that your regex sampled worked because you did not include &amp;lt; 37 &amp;gt; 1 at the front of each line. After I added &amp;lt; 37 &amp;gt; 1 the alignment shifted and the text were not highlighted correctly anymore &lt;BR /&gt;
I have attached the updated link with the correct sample text &lt;/P&gt;</description>
      <pubDate>Tue, 24 Apr 2018 00:52:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-field-with-varying-lengths-of-field-values/m-p/355620#M170120</guid>
      <dc:creator>gilbxrtx_7</dc:creator>
      <dc:date>2018-04-24T00:52:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a field with varying lengths of field values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-field-with-varying-lengths-of-field-values/m-p/355621#M170121</link>
      <description>&lt;P&gt;I realized what you meant, but I do not want to extract fields while searching, I want to create a fixed field.&lt;/P&gt;</description>
      <pubDate>Tue, 24 Apr 2018 01:02:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-field-with-varying-lengths-of-field-values/m-p/355621#M170121</guid>
      <dc:creator>gilbxrtx_7</dc:creator>
      <dc:date>2018-04-24T01:02:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a field with varying lengths of field values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-field-with-varying-lengths-of-field-values/m-p/355622#M170122</link>
      <description>&lt;P&gt;I realized what you meant, but I do not want to extract fields while searching, I want to create a fixed field.&lt;/P&gt;</description>
      <pubDate>Tue, 24 Apr 2018 01:02:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-field-with-varying-lengths-of-field-values/m-p/355622#M170122</guid>
      <dc:creator>gilbxrtx_7</dc:creator>
      <dc:date>2018-04-24T01:02:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a field with varying lengths of field values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-field-with-varying-lengths-of-field-values/m-p/355623#M170123</link>
      <description>&lt;P&gt;This is the regular expression generated by Splunk which extracted wrongly. &lt;BR /&gt;
^(?:[^ \n]* ){3}(?P\w+\s+\w+) &lt;/P&gt;</description>
      <pubDate>Tue, 24 Apr 2018 01:05:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-field-with-varying-lengths-of-field-values/m-p/355623#M170123</guid>
      <dc:creator>gilbxrtx_7</dc:creator>
      <dc:date>2018-04-24T01:05:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a field with varying lengths of field values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-field-with-varying-lengths-of-field-values/m-p/355624#M170124</link>
      <description>&lt;P&gt;Try this to create a field with all texts within the square brackets.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rex "\s*\[(?P&amp;lt;Fieldname&amp;gt;.*?)\]\s*"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 24 Apr 2018 04:30:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-field-with-varying-lengths-of-field-values/m-p/355624#M170124</guid>
      <dc:creator>kthammireddygar</dc:creator>
      <dc:date>2018-04-24T04:30:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a field with varying lengths of field values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-field-with-varying-lengths-of-field-values/m-p/355625#M170125</link>
      <description>&lt;P&gt;this is not what I'm asking for in this question&lt;BR /&gt;
@kthammireddygari&lt;/P&gt;</description>
      <pubDate>Tue, 24 Apr 2018 06:47:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-field-with-varying-lengths-of-field-values/m-p/355625#M170125</guid>
      <dc:creator>gilbxrtx_7</dc:creator>
      <dc:date>2018-04-24T06:47:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a field with varying lengths of field values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-field-with-varying-lengths-of-field-values/m-p/355626#M170126</link>
      <description>&lt;P&gt;Here it is a working complete example with the extraction of "field1"&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults count=2
| streamstats count
| eval _raw=case(count==1,"&amp;lt;37&amp;gt; 1 2018-04-23T08:08:08Z E876876876 SECURE AUDIT 0 &amp;lt;secure audit error&amp;gt; [cdkncdckne dckmdkcmd]",count==2,"&amp;lt;37&amp;gt; 1 2018-04-23T08:08:08Z E876876876 auth 0 &amp;lt;login&amp;gt; [kdnckn rrgrr]
&amp;lt;37&amp;gt; 1 2018-04-23T08:08:08Z E876876876 auth 0 &amp;lt;login&amp;gt; [kdnckn rrgrr]")
| rex field=_raw "&amp;lt;\d+&amp;gt;\s+\d+\s+(?:[^\s]+\s){2}(?P&amp;lt;field1&amp;gt;[^\s]+(?:\s+\w+)*)\s\d+\s+&amp;lt;"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/4812i1F0141C5E148A477/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Apr 2018 12:38:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-field-with-varying-lengths-of-field-values/m-p/355626#M170126</guid>
      <dc:creator>cafissimo</dc:creator>
      <dc:date>2018-04-24T12:38:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a field with varying lengths of field values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-field-with-varying-lengths-of-field-values/m-p/355627#M170127</link>
      <description>&lt;P&gt;Go to &lt;A href="http://regex101.com"&gt;http://regex101.com&lt;/A&gt; and build it yourself.  You should not be using Splunk's regex builder.&lt;/P&gt;</description>
      <pubDate>Thu, 10 May 2018 05:12:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-field-with-varying-lengths-of-field-values/m-p/355627#M170127</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2018-05-10T05:12:47Z</dc:date>
    </item>
  </channel>
</rss>

