<?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: I want rex command to return empty string if no match in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/I-want-rex-command-to-return-empty-string-if-no-match/m-p/698290#M237135</link>
    <description>&lt;P&gt;Exactly what I needed. Thanks!&lt;/P&gt;</description>
    <pubDate>Thu, 05 Sep 2024 13:40:43 GMT</pubDate>
    <dc:creator>jbrenner</dc:creator>
    <dc:date>2024-09-05T13:40:43Z</dc:date>
    <item>
      <title>I want rex command to return empty string if no match</title>
      <link>https://community.splunk.com/t5/Splunk-Search/I-want-rex-command-to-return-empty-string-if-no-match/m-p/698209#M237122</link>
      <description>&lt;P&gt;Let's say I have the following SPL query.&amp;nbsp; Ignore the regexes, thery're not important for the example:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=abc
| rex field=MESSAGE "aaa(?&amp;lt;FIELD1&amp;gt;bbb)" 
| rex field=MESSAGE "ccc(?&amp;lt;FIELD2&amp;gt;ddd)"
stats count by FIELD1, FIELD2&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Right now, the query doesn't return a result unless both fields match, but I still want to return a result if only one field matches.&amp;nbsp; I just want to return an empty string in the field that doesn't match.&amp;nbsp; Is there a way to do this? Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 04 Sep 2024 15:31:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/I-want-rex-command-to-return-empty-string-if-no-match/m-p/698209#M237122</guid>
      <dc:creator>jbrenner</dc:creator>
      <dc:date>2024-09-04T15:31:20Z</dc:date>
    </item>
    <item>
      <title>Re: I want rex command to return empty string if no match</title>
      <link>https://community.splunk.com/t5/Splunk-Search/I-want-rex-command-to-return-empty-string-if-no-match/m-p/698211#M237123</link>
      <description>&lt;P&gt;Use an empty alternative&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| rex field=MESSAGE "aaa(?&amp;lt;FIELD1&amp;gt;bbb|)" 
| rex field=MESSAGE "ccc(?&amp;lt;FIELD2&amp;gt;ddd|)"&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 04 Sep 2024 15:46:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/I-want-rex-command-to-return-empty-string-if-no-match/m-p/698211#M237123</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2024-09-04T15:46:10Z</dc:date>
    </item>
    <item>
      <title>Re: I want rex command to return empty string if no match</title>
      <link>https://community.splunk.com/t5/Splunk-Search/I-want-rex-command-to-return-empty-string-if-no-match/m-p/698240#M237125</link>
      <description>&lt;P&gt;A common approach is to use fillnull.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=abc
| rex field=MESSAGE "aaa(?&amp;lt;FIELD1&amp;gt;bbb)" 
| rex field=MESSAGE "ccc(?&amp;lt;FIELD2&amp;gt;ddd)"
| fillnull FIELD1 FIELD2 value=UNSPEC
| stats count by FIELD1, FIELD2
| foreach FIELD1 FIELD2
    [eval &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt; = if(&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt; == "UNSPEC", null(), &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;)]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is a made-up dataset based on your regex.&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;MESSAGE&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;aaabbbcccddd&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;aaabbbcccdef&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;aaabccccddd&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;abcdefg&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;The above method gives&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;FIELD1&lt;/TD&gt;&lt;TD&gt;FIELD2&lt;/TD&gt;&lt;TD&gt;count&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;ddd&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;bbb&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;bbb&lt;/TD&gt;&lt;TD&gt;ddd&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;Here is an emulation to produce this data&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults format=csv data="MESSAGE
aaabbbcccddd
aaabbbcccdef
aaabccccddd
abcdefg"
``` the above emulates
index=abc
```&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Play with it and compare with real data.&lt;/P&gt;</description>
      <pubDate>Wed, 04 Sep 2024 22:35:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/I-want-rex-command-to-return-empty-string-if-no-match/m-p/698240#M237125</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2024-09-04T22:35:52Z</dc:date>
    </item>
    <item>
      <title>Re: I want rex command to return empty string if no match</title>
      <link>https://community.splunk.com/t5/Splunk-Search/I-want-rex-command-to-return-empty-string-if-no-match/m-p/698290#M237135</link>
      <description>&lt;P&gt;Exactly what I needed. Thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 05 Sep 2024 13:40:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/I-want-rex-command-to-return-empty-string-if-no-match/m-p/698290#M237135</guid>
      <dc:creator>jbrenner</dc:creator>
      <dc:date>2024-09-05T13:40:43Z</dc:date>
    </item>
  </channel>
</rss>

