<?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: how to remove start and last character from field value in splunk using single command in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/how-to-remove-start-and-last-character-from-field-value-in/m-p/354706#M170153</link>
    <description>&lt;P&gt;Can You try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval test="road-car,a_road_car-ts,road-bus,a_road_bus-ts"
| makemv delim="," test
| mvexpand test
| rex field=test "(?&amp;lt;test&amp;gt;road[-_][^-]*)"
| replace *_* with *-* IN test
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;In your request:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;Your_searcg&amp;gt; |  rex field=test "(?&amp;lt;test&amp;gt;road[-_][^-]*)" | replace *_* with *-* IN test
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 21 Apr 2018 19:54:38 GMT</pubDate>
    <dc:creator>TISKAR</dc:creator>
    <dc:date>2018-04-21T19:54:38Z</dc:date>
    <item>
      <title>how to remove start and last character from field value in splunk using single command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/how-to-remove-start-and-last-character-from-field-value-in/m-p/354703#M170150</link>
      <description>&lt;P&gt;how to remove start and last character from field value please find the example below&lt;/P&gt;

&lt;P&gt;Example&lt;/P&gt;

&lt;P&gt;test=road-car&lt;BR /&gt;
test=a_road_car-ts&lt;BR /&gt;
test=road-bus&lt;BR /&gt;
test=a_road_bus-ts&lt;/P&gt;

&lt;P&gt;if i execute stats value result must be road-car=2 and road-bus=2&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 19:11:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/how-to-remove-start-and-last-character-from-field-value-in/m-p/354703#M170150</guid>
      <dc:creator>n4niyaz</dc:creator>
      <dc:date>2020-09-29T19:11:20Z</dc:date>
    </item>
    <item>
      <title>Re: how to remove start and last character from field value in splunk using single command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/how-to-remove-start-and-last-character-from-field-value-in/m-p/354704#M170151</link>
      <description>&lt;P&gt;Can you try the following:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; &amp;lt;yourSearch&amp;gt;
| stats count(eval(match(test,"car"))) as road-car count(eval(match(test,"bus"))) as road-bus
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Following is a run anywhere search based on sample data provided.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval data="test=road-car;test=a_road_car-ts;test=road-bus;test=a_road_bus-ts"
| makemv data delim=";"
| mvexpand data
| rename data as _raw
| KV
| stats count(eval(match(test,"car"))) as road-car count(eval(match(test,"bus"))) as road-bus
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 21 Apr 2018 18:42:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/how-to-remove-start-and-last-character-from-field-value-in/m-p/354704#M170151</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2018-04-21T18:42:34Z</dc:date>
    </item>
    <item>
      <title>Re: how to remove start and last character from field value in splunk using single command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/how-to-remove-start-and-last-character-from-field-value-in/m-p/354705#M170152</link>
      <description>&lt;P&gt;The title of your post implies removal of a single character from each end of the field, however, your examples remove multiple characters.  There's also a mix of hyphens and underscores.  Using your examples as a template, this &lt;CODE&gt;rex&lt;/CODE&gt; command should do the job for you.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | rex field=test "(?:\w_)?(?&amp;lt;foo&amp;gt;[-\w]+)(?:-\w\w)?" | stats count by foo | ...
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 21 Apr 2018 18:46:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/how-to-remove-start-and-last-character-from-field-value-in/m-p/354705#M170152</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2018-04-21T18:46:32Z</dc:date>
    </item>
    <item>
      <title>Re: how to remove start and last character from field value in splunk using single command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/how-to-remove-start-and-last-character-from-field-value-in/m-p/354706#M170153</link>
      <description>&lt;P&gt;Can You try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval test="road-car,a_road_car-ts,road-bus,a_road_bus-ts"
| makemv delim="," test
| mvexpand test
| rex field=test "(?&amp;lt;test&amp;gt;road[-_][^-]*)"
| replace *_* with *-* IN test
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;In your request:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;Your_searcg&amp;gt; |  rex field=test "(?&amp;lt;test&amp;gt;road[-_][^-]*)" | replace *_* with *-* IN test
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 21 Apr 2018 19:54:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/how-to-remove-start-and-last-character-from-field-value-in/m-p/354706#M170153</guid>
      <dc:creator>TISKAR</dc:creator>
      <dc:date>2018-04-21T19:54:38Z</dc:date>
    </item>
    <item>
      <title>Re: how to remove start and last character from field value in splunk using single command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/how-to-remove-start-and-last-character-from-field-value-in/m-p/354707#M170154</link>
      <description>&lt;P&gt;Like this (the secret sauce is in the &lt;CODE&gt;sed&lt;/CODE&gt; command; you may need to adjust the &lt;CODE&gt;2&lt;/CODE&gt; to something different.):&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults|eval test="road-car a_road_car-ts road-bus a_road_bus-ts"
| makemv test
| mvexpand test
| rex field=test mode=sed "s/_/-/g s/^[^-]{1,2}[-]// s/[-][^-]{1,2}$//"
| stats count BY test
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 22 Apr 2018 16:43:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/how-to-remove-start-and-last-character-from-field-value-in/m-p/354707#M170154</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2018-04-22T16:43:33Z</dc:date>
    </item>
  </channel>
</rss>

