<?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: Why is my query with the eval command not replacing dashes (MAC Address Formats)? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Why-is-my-query-with-the-eval-command-not-replacing-dashes-MAC/m-p/376576#M110561</link>
    <description>&lt;P&gt;Just use a better RegEx this skips over whatever is there (if anything).  Try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;$macaddress$
| rex field=$macaddress$ "^(?&amp;lt;octet1&amp;gt;\w{2})\W*(?&amp;lt;octet2&amp;gt;\w{2})\W*(?&amp;lt;octet3&amp;gt;\w{2})\W*(?&amp;lt;octet4&amp;gt;\w{2})\W*(?&amp;lt;octet5&amp;gt;\w{2})\W*(?&amp;lt;octet6&amp;gt;\w{2})$"
| dedup octet1
| table octet1 octet2 octet3 octet4 octet5 octet6
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;P.S.  Your problem was almost certainly the double-quotes in &lt;CODE&gt;replace("$macaddress$"&lt;/CODE&gt;.&lt;/P&gt;</description>
    <pubDate>Mon, 11 Feb 2019 08:25:22 GMT</pubDate>
    <dc:creator>woodcock</dc:creator>
    <dc:date>2019-02-11T08:25:22Z</dc:date>
    <item>
      <title>Why is my query with the eval command not replacing dashes (MAC Address Formats)?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-is-my-query-with-the-eval-command-not-replacing-dashes-MAC/m-p/376571#M110556</link>
      <description>&lt;P&gt;so, I'm working on implementing this:&lt;/P&gt;

&lt;P&gt;&lt;A href="https://answers.splunk.com/answers/588964/how-can-we-make-multiple-mac-address-formats-be-re.html"&gt;https://answers.splunk.com/answers/588964/how-can-we-make-multiple-mac-address-formats-be-re.html&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;In conjunction with:&lt;/P&gt;

&lt;P&gt;&lt;A href="https://answers.splunk.com/answers/472849/how-to-set-a-field-as-the-token-to-use-in-a-dashbo.html"&gt;https://answers.splunk.com/answers/472849/how-to-set-a-field-as-the-token-to-use-in-a-dashbo.html&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;And I am very close.&lt;/P&gt;

&lt;P&gt;This is dependent on an eval that replaces either colon(:) or dashes(-) and returns the MacAddress as a string of octets.&lt;/P&gt;

&lt;P&gt;The eval function:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;$macaddress$
      | eval MAC=replace("$macaddress$","[\s.:-]","")
      | rex field=MAC "^(?&amp;lt;octet1&amp;gt;..)(?&amp;lt;octet2&amp;gt;..)(?&amp;lt;octet3&amp;gt;..)(?&amp;lt;octet4&amp;gt;..)(?&amp;lt;octet5&amp;gt;..)(?&amp;lt;octet6&amp;gt;..)$"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Now, the problem here is that it works great if the macaddress is colon delimited..&lt;BR /&gt;
e.g. 00:00:00:00:00:00&lt;/P&gt;

&lt;P&gt;But, it fails to eval if there are dashes--- e.g. 00-00-00-00-00-00 or if there are no delimiters&lt;/P&gt;

&lt;P&gt;Full Search (with set token):&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;        &amp;lt;search&amp;gt;
          &amp;lt;done&amp;gt;
            &amp;lt;set token="octet1"&amp;gt;$result.octet1$&amp;lt;/set&amp;gt;
            &amp;lt;set token="octet2"&amp;gt;$result.octet2$&amp;lt;/set&amp;gt;
            &amp;lt;set token="octet3"&amp;gt;$result.octet3$&amp;lt;/set&amp;gt;
            &amp;lt;set token="octet4"&amp;gt;$result.octet4$&amp;lt;/set&amp;gt;
            &amp;lt;set token="octet5"&amp;gt;$result.octet5$&amp;lt;/set&amp;gt;
            &amp;lt;set token="octet6"&amp;gt;$result.octet6$&amp;lt;/set&amp;gt;
          &amp;lt;/done&amp;gt;
          &amp;lt;query&amp;gt;$macaddress$
| eval MAC=replace("$macaddress$","[\s.:-]","")
          | rex field=MAC "^(?&amp;amp;lt;octet1&amp;amp;gt;..)(?&amp;amp;lt;octet2&amp;amp;gt;..)(?&amp;amp;lt;octet3&amp;amp;gt;..)(?&amp;amp;lt;octet4&amp;amp;gt;..)(?&amp;amp;lt;octet5&amp;amp;gt;..)(?&amp;amp;lt;octet6&amp;amp;gt;..)$"
          | dedup octet1
| table octet1 octet2 octet3 octet4 octet5 octet6&amp;lt;/query&amp;gt;
          &amp;lt;earliest&amp;gt;$field2.earliest$&amp;lt;/earliest&amp;gt;
          &amp;lt;latest&amp;gt;$field2.latest$&amp;lt;/latest&amp;gt;
        &amp;lt;/search&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 17 Dec 2018 18:19:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-is-my-query-with-the-eval-command-not-replacing-dashes-MAC/m-p/376571#M110556</guid>
      <dc:creator>richardphung</dc:creator>
      <dc:date>2018-12-17T18:19:40Z</dc:date>
    </item>
    <item>
      <title>Re: Why is my query with the eval command not replacing dashes (MAC Address Formats)?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-is-my-query-with-the-eval-command-not-replacing-dashes-MAC/m-p/376572#M110557</link>
      <description>&lt;P&gt;In regex a dash in a character class (square brackets) has to be the first thing listed:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | eval MAC=replace("$macaddress$","[-\s.:]","")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 17 Dec 2018 19:00:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-is-my-query-with-the-eval-command-not-replacing-dashes-MAC/m-p/376572#M110557</guid>
      <dc:creator>twinspop</dc:creator>
      <dc:date>2018-12-17T19:00:17Z</dc:date>
    </item>
    <item>
      <title>Re: Why is my query with the eval command not replacing dashes (MAC Address Formats)?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-is-my-query-with-the-eval-command-not-replacing-dashes-MAC/m-p/376573#M110558</link>
      <description>&lt;P&gt;Still no go.&lt;/P&gt;

&lt;P&gt;In fact, it doesn't evaluate even if I use dash, explicit:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval MAC=replace("$macaddress$","-","")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 17 Dec 2018 19:55:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-is-my-query-with-the-eval-command-not-replacing-dashes-MAC/m-p/376573#M110558</guid>
      <dc:creator>richardphung</dc:creator>
      <dc:date>2018-12-17T19:55:34Z</dc:date>
    </item>
    <item>
      <title>Re: Why is my query with the eval command not replacing dashes (MAC Address Formats)?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-is-my-query-with-the-eval-command-not-replacing-dashes-MAC/m-p/376574#M110559</link>
      <description>&lt;P&gt;Possibly its not a normal dash? Why not replace everything that's not alphanumeric? &lt;CODE&gt;replace("$macaddress$","[^A-Za-z0-9]*","")&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Dec 2018 20:13:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-is-my-query-with-the-eval-command-not-replacing-dashes-MAC/m-p/376574#M110559</guid>
      <dc:creator>twinspop</dc:creator>
      <dc:date>2018-12-17T20:13:17Z</dc:date>
    </item>
    <item>
      <title>Re: Why is my query with the eval command not replacing dashes (MAC Address Formats)?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-is-my-query-with-the-eval-command-not-replacing-dashes-MAC/m-p/376575#M110560</link>
      <description>&lt;P&gt;That make sense...&lt;BR /&gt;
but it's not liking that either.&lt;BR /&gt;
Using:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;replace("$macaddress$","[^A-Za-z0-9]*","")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Any special character other than a colon doesn't work.&lt;BR /&gt;
e.g. 00@00@00@00@00@00&lt;/P&gt;</description>
      <pubDate>Mon, 17 Dec 2018 20:32:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-is-my-query-with-the-eval-command-not-replacing-dashes-MAC/m-p/376575#M110560</guid>
      <dc:creator>richardphung</dc:creator>
      <dc:date>2018-12-17T20:32:59Z</dc:date>
    </item>
    <item>
      <title>Re: Why is my query with the eval command not replacing dashes (MAC Address Formats)?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-is-my-query-with-the-eval-command-not-replacing-dashes-MAC/m-p/376576#M110561</link>
      <description>&lt;P&gt;Just use a better RegEx this skips over whatever is there (if anything).  Try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;$macaddress$
| rex field=$macaddress$ "^(?&amp;lt;octet1&amp;gt;\w{2})\W*(?&amp;lt;octet2&amp;gt;\w{2})\W*(?&amp;lt;octet3&amp;gt;\w{2})\W*(?&amp;lt;octet4&amp;gt;\w{2})\W*(?&amp;lt;octet5&amp;gt;\w{2})\W*(?&amp;lt;octet6&amp;gt;\w{2})$"
| dedup octet1
| table octet1 octet2 octet3 octet4 octet5 octet6
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;P.S.  Your problem was almost certainly the double-quotes in &lt;CODE&gt;replace("$macaddress$"&lt;/CODE&gt;.&lt;/P&gt;</description>
      <pubDate>Mon, 11 Feb 2019 08:25:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-is-my-query-with-the-eval-command-not-replacing-dashes-MAC/m-p/376576#M110561</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-02-11T08:25:22Z</dc:date>
    </item>
  </channel>
</rss>

