<?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 How do I filter events and extract fields in a single regular expression command in Splunk Dev</title>
    <link>https://community.splunk.com/t5/Splunk-Dev/How-do-I-filter-events-and-extract-fields-in-a-single-regular/m-p/261433#M3246</link>
    <description>&lt;P&gt;Q1:&lt;BR /&gt;
How do I merge these two regular expressions? (which are identical but one for filtering events, the other for extracting fields)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;I am | regex _raw = "I am (?&amp;lt;Name&amp;gt;.*)" | rex "I am (?&amp;lt;Name&amp;gt;.*)" | stats count Count by Name
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Q2:&lt;BR /&gt;
I already tried&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;I am | setfields Name = 0 | rex "I am (?&amp;lt;Name&amp;gt;.*)" | where Name != 0 | stats count Count by Name
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Somehow it didn't work, until I changed &lt;CODE&gt;where Name != 0&lt;/CODE&gt; to &lt;CODE&gt;where not Name = 0&lt;/CODE&gt;.&lt;/P&gt;

&lt;P&gt;From what I learnt in other answers, the behavior of &lt;CODE&gt;Name != 0&lt;/CODE&gt; and &lt;CODE&gt;not Name = 0&lt;/CODE&gt; would differ when &lt;CODE&gt;Name&lt;/CODE&gt; doesn't exist, but in this case &lt;CODE&gt;Name&lt;/CODE&gt; should always exist after &lt;CODE&gt;setfields Name = 0&lt;/CODE&gt;.&lt;/P&gt;

&lt;P&gt;Did I miss something?&lt;/P&gt;</description>
    <pubDate>Thu, 24 Mar 2016 18:00:35 GMT</pubDate>
    <dc:creator>chrisxue815</dc:creator>
    <dc:date>2016-03-24T18:00:35Z</dc:date>
    <item>
      <title>How do I filter events and extract fields in a single regular expression command</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/How-do-I-filter-events-and-extract-fields-in-a-single-regular/m-p/261433#M3246</link>
      <description>&lt;P&gt;Q1:&lt;BR /&gt;
How do I merge these two regular expressions? (which are identical but one for filtering events, the other for extracting fields)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;I am | regex _raw = "I am (?&amp;lt;Name&amp;gt;.*)" | rex "I am (?&amp;lt;Name&amp;gt;.*)" | stats count Count by Name
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Q2:&lt;BR /&gt;
I already tried&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;I am | setfields Name = 0 | rex "I am (?&amp;lt;Name&amp;gt;.*)" | where Name != 0 | stats count Count by Name
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Somehow it didn't work, until I changed &lt;CODE&gt;where Name != 0&lt;/CODE&gt; to &lt;CODE&gt;where not Name = 0&lt;/CODE&gt;.&lt;/P&gt;

&lt;P&gt;From what I learnt in other answers, the behavior of &lt;CODE&gt;Name != 0&lt;/CODE&gt; and &lt;CODE&gt;not Name = 0&lt;/CODE&gt; would differ when &lt;CODE&gt;Name&lt;/CODE&gt; doesn't exist, but in this case &lt;CODE&gt;Name&lt;/CODE&gt; should always exist after &lt;CODE&gt;setfields Name = 0&lt;/CODE&gt;.&lt;/P&gt;

&lt;P&gt;Did I miss something?&lt;/P&gt;</description>
      <pubDate>Thu, 24 Mar 2016 18:00:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/How-do-I-filter-events-and-extract-fields-in-a-single-regular/m-p/261433#M3246</guid>
      <dc:creator>chrisxue815</dc:creator>
      <dc:date>2016-03-24T18:00:35Z</dc:date>
    </item>
    <item>
      <title>Re: How do I filter events and extract fields in a single regular expression command</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/How-do-I-filter-events-and-extract-fields-in-a-single-regular/m-p/261434#M3247</link>
      <description>&lt;P&gt;What are you trying to do? &lt;/P&gt;</description>
      <pubDate>Thu, 24 Mar 2016 18:39:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/How-do-I-filter-events-and-extract-fields-in-a-single-regular/m-p/261434#M3247</guid>
      <dc:creator>michael_kushma</dc:creator>
      <dc:date>2016-03-24T18:39:58Z</dc:date>
    </item>
    <item>
      <title>Re: How do I filter events and extract fields in a single regular expression command</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/How-do-I-filter-events-and-extract-fields-in-a-single-regular/m-p/261435#M3248</link>
      <description>&lt;P&gt;Bottom line is you don't do both in same regex. It looks like you are trying to only count by Name when there is a value for Name. Try this...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;I am | regex _raw = "I am (?&amp;lt;Name&amp;gt;.*)" | stats count AS Count by Name
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Stats will only count the when there is a value for Name. &lt;/P&gt;

&lt;P&gt;Should get same results with this where the search Name=* requires Name.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;I am | regex _raw = "I am (?&amp;lt;Name&amp;gt;.*)" | search Name=* | stats count AS Count by Name
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 25 Mar 2016 04:12:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/How-do-I-filter-events-and-extract-fields-in-a-single-regular/m-p/261435#M3248</guid>
      <dc:creator>snoobzilla</dc:creator>
      <dc:date>2016-03-25T04:12:50Z</dc:date>
    </item>
  </channel>
</rss>

