<?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: Regex with conditional statement in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Regex-with-conditional-statement/m-p/346860#M102691</link>
    <description>&lt;P&gt;have you indexed your xml log ?&lt;BR /&gt;
if not then you can separate events on the basis of start/end of tag&lt;BR /&gt;
like here in your case I supposed your starting tag is &lt;CODE&gt;&amp;lt;Cust&amp;gt;&lt;/CODE&gt; so on the the basis of this I have separated events  .&lt;BR /&gt;
refer LINE_BREAKER =  part in docs&lt;BR /&gt;
&lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/Admin/Propsconf?utm_source=answers&amp;amp;utm_medium=in-comment&amp;amp;utm_term=props.conf&amp;amp;utm_campaign=refdoc" target="_blank"&gt;http://docs.splunk.com/Documentation/Splunk/latest/Admin/Propsconf?utm_source=answers&amp;amp;utm_medium=in-comment&amp;amp;utm_term=props.conf&amp;amp;utm_campaign=refdoc&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 29 Sep 2020 17:57:45 GMT</pubDate>
    <dc:creator>493669</dc:creator>
    <dc:date>2020-09-29T17:57:45Z</dc:date>
    <item>
      <title>Regex with conditional statement</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-with-conditional-statement/m-p/346856#M102687</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;

&lt;P&gt;I need some help to form regex command. My requirement is to first search for code=SEND then stats count the CountryCode, secondly search for code=RECEIVE then stats count the CountryCode.&lt;/P&gt;

&lt;P&gt;This is my XML log:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;                    &amp;lt;Cust&amp;gt;
                    &amp;lt;Code&amp;gt;SEND&amp;lt;/Code&amp;gt;
                           &amp;lt;CountryCode&amp;gt;CN&amp;lt;/CountryCode&amp;gt;
                           &amp;lt;Lty&amp;gt;
                              &amp;lt;CtyNm&amp;gt;BEIJING&amp;lt;/CtyNm&amp;gt;
                              &amp;lt;Zip&amp;gt;100176&amp;lt;/Zip&amp;gt;
                           &amp;lt;/Lty&amp;gt;
                  &amp;lt;/Cust&amp;gt;
                  &amp;lt;Cust&amp;gt;
                     &amp;lt;Code&amp;gt;RECEIVE&amp;lt;/Code&amp;gt;
                           &amp;lt;CountryCode&amp;gt;JP&amp;lt;/CountryCode&amp;gt;
                           &amp;lt;Lty&amp;gt;
                              &amp;lt;CtyNm&amp;gt;TOKYO&amp;lt;/CtyNm&amp;gt;
                              &amp;lt;Zip&amp;gt;1000001&amp;lt;/Zip&amp;gt;
                           &amp;lt;/Lty&amp;gt;
                  &amp;lt;/Cust&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I'm having this query formed but not meeting the above requirement, it only matches the first code=SEND and perform the count.&lt;/P&gt;

&lt;P&gt;index=* &lt;BR /&gt;
| rex "(?P[\w+\s+]+)" &lt;BR /&gt;
| stats count by country&lt;/P&gt;

&lt;P&gt;Appreciate for your help.&lt;/P&gt;</description>
      <pubDate>Tue, 06 Feb 2018 03:24:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-with-conditional-statement/m-p/346856#M102687</guid>
      <dc:creator>krusovice</dc:creator>
      <dc:date>2018-02-06T03:24:32Z</dc:date>
    </item>
    <item>
      <title>Re: Regex with conditional statement</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-with-conditional-statement/m-p/346857#M102688</link>
      <description>&lt;P&gt;is this only one event? why you have not separated event on basis of  tag&lt;/P&gt;</description>
      <pubDate>Tue, 06 Feb 2018 04:08:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-with-conditional-statement/m-p/346857#M102688</guid>
      <dc:creator>493669</dc:creator>
      <dc:date>2018-02-06T04:08:11Z</dc:date>
    </item>
    <item>
      <title>Re: Regex with conditional statement</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-with-conditional-statement/m-p/346858#M102689</link>
      <description>&lt;P&gt;If you do the ingestion in such a way that each   is a separate event in Splunk with valid xml syntax, the field extraction can be done by adding &lt;CODE&gt;KV_MODE = xml&lt;/CODE&gt; in props.conf on Search Head(s). So, main focus should be getting the data ingested correctly. if your data doesn't have timestamp then here current time is considered as  the _time value for the event.&lt;/P&gt;

&lt;P&gt;Try this for props.conf on your Indexer/Heavy Forwarder.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; [SourceType_name]
 SHOULD_LINEMERGE = false
 LINE_BREAKER = ([\r\n]+)(?=\s*\&amp;lt;Cust\&amp;gt;)
 DATETIME_CONFIG = CURRENT
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Search head props.conf&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; [SourceType_name]
 KV_MODE =xml
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If you separate events on the basis of tag then it will be easier to perform evaluation&lt;/P&gt;</description>
      <pubDate>Tue, 06 Feb 2018 04:26:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-with-conditional-statement/m-p/346858#M102689</guid>
      <dc:creator>493669</dc:creator>
      <dc:date>2018-02-06T04:26:56Z</dc:date>
    </item>
    <item>
      <title>Re: Regex with conditional statement</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-with-conditional-statement/m-p/346859#M102690</link>
      <description>&lt;P&gt;I'm not familiar with props.conf, the  ...  is nested inside a long output of XML, and there are many events with these tags. Could you further explain by editing props.conf, how can I achieve what I needed to query?&lt;/P&gt;</description>
      <pubDate>Tue, 06 Feb 2018 05:08:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-with-conditional-statement/m-p/346859#M102690</guid>
      <dc:creator>krusovice</dc:creator>
      <dc:date>2018-02-06T05:08:21Z</dc:date>
    </item>
    <item>
      <title>Re: Regex with conditional statement</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-with-conditional-statement/m-p/346860#M102691</link>
      <description>&lt;P&gt;have you indexed your xml log ?&lt;BR /&gt;
if not then you can separate events on the basis of start/end of tag&lt;BR /&gt;
like here in your case I supposed your starting tag is &lt;CODE&gt;&amp;lt;Cust&amp;gt;&lt;/CODE&gt; so on the the basis of this I have separated events  .&lt;BR /&gt;
refer LINE_BREAKER =  part in docs&lt;BR /&gt;
&lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/Admin/Propsconf?utm_source=answers&amp;amp;utm_medium=in-comment&amp;amp;utm_term=props.conf&amp;amp;utm_campaign=refdoc" target="_blank"&gt;http://docs.splunk.com/Documentation/Splunk/latest/Admin/Propsconf?utm_source=answers&amp;amp;utm_medium=in-comment&amp;amp;utm_term=props.conf&amp;amp;utm_campaign=refdoc&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 17:57:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-with-conditional-statement/m-p/346860#M102691</guid>
      <dc:creator>493669</dc:creator>
      <dc:date>2020-09-29T17:57:45Z</dc:date>
    </item>
    <item>
      <title>Re: Regex with conditional statement</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-with-conditional-statement/m-p/346861#M102692</link>
      <description>&lt;P&gt;Thanks for explaining and I got your point now. The log already indexed and I can't un-do it since I'm not admin. Furthermore, the log is not purely just XML but with other text and SOAP messages as well.&lt;/P&gt;</description>
      <pubDate>Tue, 06 Feb 2018 05:29:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-with-conditional-statement/m-p/346861#M102692</guid>
      <dc:creator>krusovice</dc:creator>
      <dc:date>2018-02-06T05:29:27Z</dc:date>
    </item>
    <item>
      <title>Re: Regex with conditional statement</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-with-conditional-statement/m-p/346862#M102693</link>
      <description>&lt;P&gt;try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;   ... |rex field=_raw max_match=0 "(?m)&amp;lt;code&amp;gt;(?&amp;lt;code&amp;gt;[^&amp;lt;]+).*(?[^&amp;lt;]+)"|eval merged=mvzip(Code,CountryCode,";;")|mvexpand merged| eval merged=split(merged,";;") | eval Code=mvindex(merged,0)| eval CountryCode=mvindex(merged,1)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;try this run anywhere search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|makeresults|eval raw="&amp;lt;Cust&amp;gt; &amp;lt;Code&amp;gt;SEND&amp;lt;/Code&amp;gt; &amp;lt;CountryCode&amp;gt;CN&amp;lt;/CountryCode&amp;gt; &amp;lt;Lty&amp;gt; &amp;lt;CtyNm&amp;gt;BEIJING&amp;lt;/CtyNm&amp;gt; &amp;lt;Zip&amp;gt;100176&amp;lt;/Zip&amp;gt; &amp;lt;/Lty&amp;gt; &amp;lt;/Cust&amp;gt;
&amp;lt;Cust&amp;gt; &amp;lt;Code&amp;gt;RECEIVE&amp;lt;/Code&amp;gt; &amp;lt;CountryCode&amp;gt;JP&amp;lt;/CountryCode&amp;gt; &amp;lt;Lty&amp;gt; &amp;lt;CtyNm&amp;gt;TOKYO&amp;lt;/CtyNm&amp;gt; &amp;lt;Zip&amp;gt;1000001&amp;lt;/Zip&amp;gt; &amp;lt;/Lty&amp;gt; &amp;lt;/Cust&amp;gt;"
|rex field=raw max_match=0 "(?m)&amp;lt;Code&amp;gt;(?&amp;lt;Code&amp;gt;[^&amp;lt;]+).*&amp;lt;CountryCode&amp;gt;(?&amp;lt;CountryCode&amp;gt;[^&amp;lt;]+)"|eval merged=mvzip(Code,CountryCode,";;")|mvexpand merged| eval merged=split(merged,";;") | eval Code=mvindex(merged,0)| eval CountryCode=mvindex(merged,1)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 06 Feb 2018 06:20:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-with-conditional-statement/m-p/346862#M102693</guid>
      <dc:creator>493669</dc:creator>
      <dc:date>2018-02-06T06:20:25Z</dc:date>
    </item>
    <item>
      <title>Re: Regex with conditional statement</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-with-conditional-statement/m-p/346863#M102694</link>
      <description>&lt;P&gt;Thank you. I get some ideas with your answer.&lt;/P&gt;</description>
      <pubDate>Tue, 06 Feb 2018 08:08:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-with-conditional-statement/m-p/346863#M102694</guid>
      <dc:creator>krusovice</dc:creator>
      <dc:date>2018-02-06T08:08:28Z</dc:date>
    </item>
  </channel>
</rss>

