<?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: Trim field for operations in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Trim-field-for-operations/m-p/64914#M16032</link>
    <description>&lt;P&gt;Do you happen to have a good tutorial for the rex syntax, specifically for trimming/removing extra characters? I'd very much appreciate it.&lt;/P&gt;</description>
    <pubDate>Thu, 24 Mar 2011 08:15:58 GMT</pubDate>
    <dc:creator>msarro</dc:creator>
    <dc:date>2011-03-24T08:15:58Z</dc:date>
    <item>
      <title>Trim field for operations</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Trim-field-for-operations/m-p/64910#M16028</link>
      <description>&lt;P&gt;Hey everyone, I have an event type containing two fields that I need to trim. They're currently in this format:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;02/09/11 at 2:56 PM","eth 0/1","NNNNNNNNNNNN","NNNNNNNNNNNN","72 ms","0","0 ms","0","4.200","G711U"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The fields I need trimmed are the "72 ms" and "0 ms". I just need the " ms" portion to be removed so I can start doing mathematical operations. The best would be removing this at index time, however I can also do it at search time. I tried using the field extractor but the regex it generates doesn't seem to make any sense.&lt;/P&gt;

&lt;P&gt;This is what it generated:
(?i)^(?:[^"]*"){9}(?P[^ ]+)&lt;/P&gt;</description>
      <pubDate>Tue, 22 Mar 2011 21:28:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Trim-field-for-operations/m-p/64910#M16028</guid>
      <dc:creator>msarro</dc:creator>
      <dc:date>2011-03-22T21:28:59Z</dc:date>
    </item>
    <item>
      <title>Re: Trim field for operations</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Trim-field-for-operations/m-p/64911#M16029</link>
      <description>&lt;P&gt;If this comes in CSV format, it might be best to use Splunk's wizardry to extract the fields early on:&lt;/P&gt;

&lt;P&gt;&lt;A href="http://www.splunk.com/base/Documentation/latest/Data/Extractfieldsfromfileheadersatindextime" rel="nofollow"&gt;http://www.splunk.com/base/Documentation/latest/Data/Extractfieldsfromfileheadersatindextime&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;If that's not an option (or so you can get up and running first), the following regex should do the trick, for the particular event you've pasted:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;YourSearch | rex field=_raw "\"(?&amp;lt;Field1&amp;gt;\d*) ms\",\"\d*\",\"(?&amp;lt;Field2&amp;gt;\d*) ms" 
           | stats avg(Field1), avg(Field2)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;You can take that regular expression and move it into props.conf as well:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[my_sourcetype]
EXTRACT-extract_two_fields = "(?&amp;lt;Field1&amp;gt;\d*) ms","\d*","(?&amp;lt;Field2&amp;gt;\d*) ms
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;(I don't believe you need to escape the quotes in props.conf -- you may need to put those escapes back in, if not).&lt;/P&gt;

&lt;P&gt;Should you have Splunk pull out the field names (as per the first link), you'd end up with ResponseTime="72 ms" and Jitter="0 ms" (or whatever those represent). You could then pull out the numbers by doing:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;YourSearch | rex field=ResponseTime "(?&amp;lt;NumResponseTime&amp;gt;\d*)" 
           | rex field=Jitter "(?&amp;lt;NumJitter&amp;gt;\d*)"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Let me know if that answers your question.&lt;/P&gt;</description>
      <pubDate>Tue, 22 Mar 2011 22:36:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Trim-field-for-operations/m-p/64911#M16029</guid>
      <dc:creator>David</dc:creator>
      <dc:date>2011-03-22T22:36:34Z</dc:date>
    </item>
    <item>
      <title>Re: Trim field for operations</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Trim-field-for-operations/m-p/64912#M16030</link>
      <description>&lt;P&gt;The insert into props.conf worked like a bell. Thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 24 Mar 2011 04:36:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Trim-field-for-operations/m-p/64912#M16030</guid>
      <dc:creator>msarro</dc:creator>
      <dc:date>2011-03-24T04:36:04Z</dc:date>
    </item>
    <item>
      <title>Re: Trim field for operations</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Trim-field-for-operations/m-p/64913#M16031</link>
      <description>&lt;P&gt;Excellent. I'm glad to hear that.&lt;/P&gt;</description>
      <pubDate>Thu, 24 Mar 2011 06:45:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Trim-field-for-operations/m-p/64913#M16031</guid>
      <dc:creator>David</dc:creator>
      <dc:date>2011-03-24T06:45:09Z</dc:date>
    </item>
    <item>
      <title>Re: Trim field for operations</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Trim-field-for-operations/m-p/64914#M16032</link>
      <description>&lt;P&gt;Do you happen to have a good tutorial for the rex syntax, specifically for trimming/removing extra characters? I'd very much appreciate it.&lt;/P&gt;</description>
      <pubDate>Thu, 24 Mar 2011 08:15:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Trim-field-for-operations/m-p/64914#M16032</guid>
      <dc:creator>msarro</dc:creator>
      <dc:date>2011-03-24T08:15:58Z</dc:date>
    </item>
    <item>
      <title>Re: Trim field for operations</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Trim-field-for-operations/m-p/64915#M16033</link>
      <description>&lt;P&gt;The Rex uses Perl Compatible Regular Expressions (PCRE).. at is at least very similar. You might get into issues where you have to escape things (such as a quote), but that you can generally figure out by starting with something simple, and building up with a little trial and error. The authoritative source for PCRE is &lt;A href="http://perldoc.perl.org/perlre.html"&gt;http://perldoc.perl.org/perlre.html&lt;/A&gt; , and if you google PCRE tutorial, or Perl Regular Expressions Tutorial, you might find a few things that are a bit more "how do I get started." This one looks promising: &lt;A href="http://www.troubleshooters.com/codecorn/littperl/perlreg.htm"&gt;http://www.troubleshooters.com/codecorn/littperl/perlreg.htm&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Mar 2011 22:31:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Trim-field-for-operations/m-p/64915#M16033</guid>
      <dc:creator>David</dc:creator>
      <dc:date>2011-03-24T22:31:21Z</dc:date>
    </item>
  </channel>
</rss>

