<?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 use Rex command to extract this field from my sample log? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-Rex-command-to-extract-this-field-from-my-sample-log/m-p/216869#M63684</link>
    <description>&lt;P&gt;Try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rex "\s(?&amp;lt;myField&amp;gt;[^\s_]+_[^\s_]+)_"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Based off of @woodcock 's answer&lt;/P&gt;

&lt;P&gt;@Abilan1 I had a typo, I have removed the second close parenthesis from my answer&lt;/P&gt;</description>
    <pubDate>Mon, 02 Nov 2015 15:02:08 GMT</pubDate>
    <dc:creator>aholzer</dc:creator>
    <dc:date>2015-11-02T15:02:08Z</dc:date>
    <item>
      <title>How to use Rex command to extract this field from my sample log?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-Rex-command-to-extract-this-field-from-my-sample-log/m-p/216860#M63675</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;Sample log file:&lt;/P&gt;

&lt;P&gt;STD QBATCH:P   GRAUT          77718 &lt;STRONG&gt;R5609812_S0000001&lt;/STRONG&gt;_5847829&lt;/P&gt;

&lt;P&gt;I want to create that highlighted term as a new event field. Only STD in that above line will be common in all over the logs, remaining words or characters may change. So I am not sure how to use Rex here. Also in the same indexed line it may occurs many time.&lt;/P&gt;

&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Mon, 02 Nov 2015 13:27:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-Rex-command-to-extract-this-field-from-my-sample-log/m-p/216860#M63675</guid>
      <dc:creator>Abilan1</dc:creator>
      <dc:date>2015-11-02T13:27:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to use Rex command to extract this field from my sample log?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-Rex-command-to-extract-this-field-from-my-sample-log/m-p/216861#M63676</link>
      <description>&lt;P&gt;Are the number of whitespaces between the "STD" and the value you want consistent?&lt;/P&gt;

&lt;P&gt;If yes, then this should do the trick:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | rex "STD\s([^\s]+\s){3}(?P&amp;lt;your_field&amp;gt;([^_]+_){2}))"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;It will store this &lt;CODE&gt;R5609812_S0000001_&lt;/CODE&gt; as the value of &lt;CODE&gt;your_field&lt;/CODE&gt;. If you don't want the second underscore in your value, you can do the following:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | eval your_field = substr(your_field,1,len(your_field)-1)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Hope this helps.&lt;/P&gt;</description>
      <pubDate>Mon, 02 Nov 2015 13:53:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-Rex-command-to-extract-this-field-from-my-sample-log/m-p/216861#M63676</guid>
      <dc:creator>aholzer</dc:creator>
      <dc:date>2015-11-02T13:53:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to use Rex command to extract this field from my sample log?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-Rex-command-to-extract-this-field-from-my-sample-log/m-p/216862#M63677</link>
      <description>&lt;P&gt;hi,&lt;/P&gt;

&lt;P&gt;Thanks for your reply! whitespaces will vary.it's not constant. &lt;/P&gt;</description>
      <pubDate>Mon, 02 Nov 2015 14:07:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-Rex-command-to-extract-this-field-from-my-sample-log/m-p/216862#M63677</guid>
      <dc:creator>Abilan1</dc:creator>
      <dc:date>2015-11-02T14:07:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to use Rex command to extract this field from my sample log?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-Rex-command-to-extract-this-field-from-my-sample-log/m-p/216863#M63678</link>
      <description>&lt;P&gt;Can you provide more samples then?&lt;/P&gt;</description>
      <pubDate>Mon, 02 Nov 2015 14:13:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-Rex-command-to-extract-this-field-from-my-sample-log/m-p/216863#M63678</guid>
      <dc:creator>aholzer</dc:creator>
      <dc:date>2015-11-02T14:13:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to use Rex command to extract this field from my sample log?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-Rex-command-to-extract-this-field-from-my-sample-log/m-p/216864#M63679</link>
      <description>&lt;P&gt;Like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rex "(?&amp;lt;myField&amp;gt;[^\s_]+_[^\s_]+)_[^\s_]+$"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 02 Nov 2015 14:13:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-Rex-command-to-extract-this-field-from-my-sample-log/m-p/216864#M63679</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2015-11-02T14:13:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to use Rex command to extract this field from my sample log?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-Rex-command-to-extract-this-field-from-my-sample-log/m-p/216865#M63680</link>
      <description>&lt;P&gt;Please find below&lt;/P&gt;

&lt;P&gt;STD QBATCH:P   ALIUYFG 54902 R5641003_A0000002_5853971   &lt;/P&gt;

&lt;P&gt;STD QBATCH:P   JUCHOI        158875 R5641003_A0000002_5870061 &lt;/P&gt;

&lt;P&gt;STD QBATCH:P   GYLUT          23335 R5609811_A0000003_5871713  &lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 07:47:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-Rex-command-to-extract-this-field-from-my-sample-log/m-p/216865#M63680</guid>
      <dc:creator>Abilan1</dc:creator>
      <dc:date>2020-09-29T07:47:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to use Rex command to extract this field from my sample log?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-Rex-command-to-extract-this-field-from-my-sample-log/m-p/216866#M63681</link>
      <description>&lt;P&gt;There are exactly 4 whitespaces between the "STD" and the value you want in every one of your samples. That seems pretty consistent.&lt;/P&gt;

&lt;P&gt;Also can you clarify what you want to capture? Is it:&lt;BR /&gt;
R5609811_A0000003_5871713&lt;BR /&gt;
or&lt;BR /&gt;
R5609811_A0000003_&lt;BR /&gt;
or&lt;BR /&gt;
R5609811_A0000003&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 07:47:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-Rex-command-to-extract-this-field-from-my-sample-log/m-p/216866#M63681</guid>
      <dc:creator>aholzer</dc:creator>
      <dc:date>2020-09-29T07:47:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to use Rex command to extract this field from my sample log?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-Rex-command-to-extract-this-field-from-my-sample-log/m-p/216867#M63682</link>
      <description>&lt;P&gt;@Abilan1 what @woodcock here has said will work - if you add a close parenthesis after the dollar sign. It will capture everything between the last whitespace and the end as "myField". You can then use substring or further rex to extract just the first parts of that field.&lt;/P&gt;</description>
      <pubDate>Mon, 02 Nov 2015 14:25:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-Rex-command-to-extract-this-field-from-my-sample-log/m-p/216867#M63682</guid>
      <dc:creator>aholzer</dc:creator>
      <dc:date>2015-11-02T14:25:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to use Rex command to extract this field from my sample log?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-Rex-command-to-extract-this-field-from-my-sample-log/m-p/216868#M63683</link>
      <description>&lt;P&gt;This one&lt;/P&gt;

&lt;P&gt;R5609811_A0000003&lt;/P&gt;</description>
      <pubDate>Mon, 02 Nov 2015 14:54:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-Rex-command-to-extract-this-field-from-my-sample-log/m-p/216868#M63683</guid>
      <dc:creator>Abilan1</dc:creator>
      <dc:date>2015-11-02T14:54:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to use Rex command to extract this field from my sample log?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-Rex-command-to-extract-this-field-from-my-sample-log/m-p/216869#M63684</link>
      <description>&lt;P&gt;Try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rex "\s(?&amp;lt;myField&amp;gt;[^\s_]+_[^\s_]+)_"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Based off of @woodcock 's answer&lt;/P&gt;

&lt;P&gt;@Abilan1 I had a typo, I have removed the second close parenthesis from my answer&lt;/P&gt;</description>
      <pubDate>Mon, 02 Nov 2015 15:02:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-Rex-command-to-extract-this-field-from-my-sample-log/m-p/216869#M63684</guid>
      <dc:creator>aholzer</dc:creator>
      <dc:date>2015-11-02T15:02:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to use Rex command to extract this field from my sample log?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-Rex-command-to-extract-this-field-from-my-sample-log/m-p/216870#M63685</link>
      <description>&lt;P&gt;hi&lt;/P&gt;

&lt;P&gt;I am getting "Regex: unmatched parentheses" error..&lt;/P&gt;</description>
      <pubDate>Mon, 02 Nov 2015 15:08:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-Rex-command-to-extract-this-field-from-my-sample-log/m-p/216870#M63685</guid>
      <dc:creator>Abilan1</dc:creator>
      <dc:date>2015-11-02T15:08:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to use Rex command to extract this field from my sample log?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-Rex-command-to-extract-this-field-from-my-sample-log/m-p/216871#M63686</link>
      <description>&lt;P&gt;I had a typo. I have edited my comment to remove it.&lt;/P&gt;

&lt;P&gt;I had a second close parenthesis.&lt;/P&gt;</description>
      <pubDate>Mon, 02 Nov 2015 15:15:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-Rex-command-to-extract-this-field-from-my-sample-log/m-p/216871#M63686</guid>
      <dc:creator>aholzer</dc:creator>
      <dc:date>2015-11-02T15:15:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to use Rex command to extract this field from my sample log?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-Rex-command-to-extract-this-field-from-my-sample-log/m-p/216872#M63687</link>
      <description>&lt;P&gt;hi,&lt;/P&gt;

&lt;P&gt;Thank You! It is capturing only 1st record from that indexed line..As I said earlier, am having more records in the same line..&lt;/P&gt;

&lt;P&gt;STD QBATCH:P ALIUYFG 54902 R5641003_A0000002_5853971&lt;/P&gt;

&lt;P&gt;STD QBATCH:P JUCHOI 158875 R5641003_A0000002_5870061&lt;/P&gt;

&lt;P&gt;STD QBATCH:P GYLUT 23335 R5609811_A0000003_5871713 &lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 07:47:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-Rex-command-to-extract-this-field-from-my-sample-log/m-p/216872#M63687</guid>
      <dc:creator>Abilan1</dc:creator>
      <dc:date>2020-09-29T07:47:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to use Rex command to extract this field from my sample log?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-Rex-command-to-extract-this-field-from-my-sample-log/m-p/216873#M63688</link>
      <description>&lt;P&gt;Do you mean that a single Splunk event can contain multiple lines from which you want to capture said field?&lt;/P&gt;

&lt;P&gt;So for example the three samples you have provided above are a single event?&lt;/P&gt;</description>
      <pubDate>Mon, 02 Nov 2015 15:26:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-Rex-command-to-extract-this-field-from-my-sample-log/m-p/216873#M63688</guid>
      <dc:creator>aholzer</dc:creator>
      <dc:date>2015-11-02T15:26:56Z</dc:date>
    </item>
  </channel>
</rss>

