<?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: Searching for a substring when using eval? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Searching-for-a-substring-when-using-eval/m-p/107240#M183347</link>
    <description>&lt;P&gt;You could, if this is common, define a macro in macros.conf to normalize the phone number, and call that in your expressions everywhere&lt;/P&gt;</description>
    <pubDate>Wed, 05 Jan 2011 01:53:13 GMT</pubDate>
    <dc:creator>gkanapathy</dc:creator>
    <dc:date>2011-01-05T01:53:13Z</dc:date>
    <item>
      <title>Searching for a substring when using eval?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Searching-for-a-substring-when-using-eval/m-p/107237#M183344</link>
      <description>&lt;P&gt;I am trying to set up a fairly simple search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="sandbox" sourcetype="as-cdr" |stats count(eval(Calling_Number=*2155551220)) AS callsMade count(eval(Called_Number=*2155551220)) AS callsRecvd
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;However I receive an error stating:&lt;/P&gt;

&lt;BLOCKQUOTE&gt;
  &lt;P&gt;Error in 'stats' command: The eval
  expression for dynamic field
  'eval(Calling_Number=*2155551220)' is
  invalid. Error='The expression is
  malformed. An unexpected character is
  reached at '*2155551220'.'&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;

&lt;P&gt;The issue that I'm encountering is that the telephone number listed sometimes appears in the Called_Number field as 12155551220, sometimes appears as +12155551220, and other times appears as 2155551220. I have attempted to perform the search using wildcards like *in front of the shortest version however it seems to only occasionally work. Is it possible to evaluate for a substring with eval?&lt;/P&gt;</description>
      <pubDate>Tue, 21 Dec 2010 11:15:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Searching-for-a-substring-when-using-eval/m-p/107237#M183344</guid>
      <dc:creator>msarro</dc:creator>
      <dc:date>2010-12-21T11:15:25Z</dc:date>
    </item>
    <item>
      <title>Re: Searching for a substring when using eval?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Searching-for-a-substring-when-using-eval/m-p/107238#M183345</link>
      <description>&lt;P&gt;One potential easier solution might be to normalize the data after the fact.  Something like this might work:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="sandbox" sourcetype="as-cdr" |
rex mode=sed field=Calling_Number "s/(+1|1)(\d{10})/\2/" |
rex mode=sed field=Called_Number "s/(+1|1)(\d{10})/\2/" |
where Calling_Number=2155551220 OR Called_Number=2155551220 |
stats count(eval(Calling_Number=2155551220)) AS callsMade 
      count(eval(Called_Number=2155551220)) AS callsRecvd
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;That should filter off a "1" or "+1" at the beginning, if it's followed by a full 10 digits.  I'm not 100% sure on the syntax, as splunk's sed differs a little from unix sed in terms of what needs a \ and what doesn't.  But, it "should" work.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Dec 2010 01:20:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Searching-for-a-substring-when-using-eval/m-p/107238#M183345</guid>
      <dc:creator>dwaddle</dc:creator>
      <dc:date>2010-12-22T01:20:56Z</dc:date>
    </item>
    <item>
      <title>Re: Searching for a substring when using eval?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Searching-for-a-substring-when-using-eval/m-p/107239#M183346</link>
      <description>&lt;P&gt;You have two problems with your use of eval:&lt;/P&gt;

&lt;UL&gt;
&lt;LI&gt;You can't use wildcard patterns with the &lt;CODE&gt;=&lt;/CODE&gt; operator in &lt;CODE&gt;eval&lt;/CODE&gt;. You would have to use either the &lt;CODE&gt;like()&lt;/CODE&gt; or &lt;CODE&gt;searchmatch()&lt;/CODE&gt; eval functions, the &lt;CODE&gt;LIKE&lt;/CODE&gt; operator, or use the &lt;CODE&gt;replace()&lt;/CODE&gt; eval function and apply the &lt;CODE&gt;=&lt;/CODE&gt; (or &lt;CODE&gt;==&lt;/CODE&gt;) operator to that.&lt;/LI&gt;
&lt;LI&gt;You need to quote strings in &lt;CODE&gt;eval&lt;/CODE&gt;. If you don't, eval tries to perform a numeric comparison (in which 0123 is equal to 123, and *123 is not a valid number).&lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;So:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;count(eval(replace(Calling_Number,"^(?:+1|1)?(.*)","\1") == "2155551220"))
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;is probably the best choice. &lt;/P&gt;</description>
      <pubDate>Wed, 05 Jan 2011 01:50:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Searching-for-a-substring-when-using-eval/m-p/107239#M183346</guid>
      <dc:creator>gkanapathy</dc:creator>
      <dc:date>2011-01-05T01:50:06Z</dc:date>
    </item>
    <item>
      <title>Re: Searching for a substring when using eval?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Searching-for-a-substring-when-using-eval/m-p/107240#M183347</link>
      <description>&lt;P&gt;You could, if this is common, define a macro in macros.conf to normalize the phone number, and call that in your expressions everywhere&lt;/P&gt;</description>
      <pubDate>Wed, 05 Jan 2011 01:53:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Searching-for-a-substring-when-using-eval/m-p/107240#M183347</guid>
      <dc:creator>gkanapathy</dc:creator>
      <dc:date>2011-01-05T01:53:13Z</dc:date>
    </item>
  </channel>
</rss>

