<?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: remove repetitive string in string in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/remove-repetitive-string-in-string/m-p/365356#M107765</link>
    <description>&lt;P&gt;Try this - &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults | eval myfield="asdw+wkas+asdw" 
| rename COMMENT as "The above creates test data"

| makemv delim="+" myfield 
| eval myfield=if(mvcount(myfield)&amp;lt;=1,myfield,"package(".mvjoin(mvdedup(myfield),"+").")")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;with resulting output...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;myfield
package(asdw+wkas)  
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Now, since you are not retaining the info on how many of each were originally there,  and since the field already had multiple values in it, you could forego the words "package()" around the altered field if you wanted.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makemv delim="+" myfield 
| eval myfield=if(mvcount(myfield)&amp;lt;=1,myfield,mvjoin(mvdedup(myfield),"+"))
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 27 Jun 2017 23:05:15 GMT</pubDate>
    <dc:creator>DalJeanis</dc:creator>
    <dc:date>2017-06-27T23:05:15Z</dc:date>
    <item>
      <title>remove repetitive string in string</title>
      <link>https://community.splunk.com/t5/Splunk-Search/remove-repetitive-string-in-string/m-p/365351#M107760</link>
      <description>&lt;P&gt;manipulating strings, I had a post before regarding an array, but say I have a field that has value &lt;CODE&gt;string1+string2+string1&lt;/CODE&gt;, how can I display this value as &lt;CODE&gt;packaged(string1+string2)&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;EDIT:&lt;BR /&gt;
I have a particular field in my logs that is displayed as &lt;CODE&gt;field="string1+string2+string1"&lt;/CODE&gt; and when I use &lt;CODE&gt;stats&lt;/CODE&gt; on this field to make a table, however, the string length can be very repetitive &lt;CODE&gt;field="string1+string1+string1+string1..."&lt;/CODE&gt; or &lt;CODE&gt;field="string1+string2+string2"&lt;/CODE&gt;, so I want to be able to basically make any string with logically more than 1 value to be displayed as &lt;CODE&gt;package(..)&lt;/CODE&gt; where the .. is the unique strings, so for &lt;CODE&gt;field="string1+string1"&lt;/CODE&gt; can be &lt;CODE&gt;packaged(string1)&lt;/CODE&gt; so does &lt;CODE&gt;field="string1+string1+string1"&lt;/CODE&gt; and so forth, for &lt;BR /&gt;
&lt;CODE&gt;field="string1+string2+string2"&lt;/CODE&gt; or &lt;CODE&gt;field="string1+string2"&lt;/CODE&gt; can be &lt;CODE&gt;packaged(string1+string2)&lt;/CODE&gt;&lt;BR /&gt;
Say each string represents different codes that are vastly different from one and another, so wildcard isnt an option.&lt;/P&gt;</description>
      <pubDate>Tue, 27 Jun 2017 20:50:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/remove-repetitive-string-in-string/m-p/365351#M107760</guid>
      <dc:creator>exocore123</dc:creator>
      <dc:date>2017-06-27T20:50:19Z</dc:date>
    </item>
    <item>
      <title>Re: remove repetitive string in string</title>
      <link>https://community.splunk.com/t5/Splunk-Search/remove-repetitive-string-in-string/m-p/365352#M107761</link>
      <description>&lt;P&gt;@exocore123, you might have to add sample values(if actual value is not possible please add anonymized string) for us to help you better.&lt;/P&gt;</description>
      <pubDate>Tue, 27 Jun 2017 21:34:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/remove-repetitive-string-in-string/m-p/365352#M107761</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-06-27T21:34:46Z</dc:date>
    </item>
    <item>
      <title>Re: remove repetitive string in string</title>
      <link>https://community.splunk.com/t5/Splunk-Search/remove-repetitive-string-in-string/m-p/365353#M107762</link>
      <description>&lt;P&gt;@niketnilay idk if that helps but i tried to be more specific&lt;/P&gt;</description>
      <pubDate>Tue, 27 Jun 2017 21:40:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/remove-repetitive-string-in-string/m-p/365353#M107762</guid>
      <dc:creator>exocore123</dc:creator>
      <dc:date>2017-06-27T21:40:51Z</dc:date>
    </item>
    <item>
      <title>Re: remove repetitive string in string</title>
      <link>https://community.splunk.com/t5/Splunk-Search/remove-repetitive-string-in-string/m-p/365354#M107763</link>
      <description>&lt;P&gt;@exocore123, by values I meant some sample data. &lt;/P&gt;

&lt;P&gt;Does your strings in the field actually have &lt;STRONG&gt;plus sign (+)&lt;/STRONG&gt; or any other delimiter between them?&lt;BR /&gt;
Does your field actually have string1 or string2 in it? Or is this sample?&lt;/P&gt;

&lt;P&gt;Or is your field value something like following?&lt;BR /&gt;
field= "abcdefabc"&lt;BR /&gt;
Where &lt;STRONG&gt;abc&lt;/STRONG&gt; is &lt;STRONG&gt;string1&lt;/STRONG&gt; and &lt;STRONG&gt;def&lt;/STRONG&gt; is &lt;STRONG&gt;string2&lt;/STRONG&gt;.&lt;/P&gt;</description>
      <pubDate>Tue, 27 Jun 2017 22:10:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/remove-repetitive-string-in-string/m-p/365354#M107763</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-06-27T22:10:10Z</dc:date>
    </item>
    <item>
      <title>Re: remove repetitive string in string</title>
      <link>https://community.splunk.com/t5/Splunk-Search/remove-repetitive-string-in-string/m-p/365355#M107764</link>
      <description>&lt;P&gt;The things I put are the literal sample data. The + sign is part of the string. It's literally &lt;CODE&gt;field="asdw+wkas+asdw"&lt;/CODE&gt;, not sure if that clarifies? &lt;/P&gt;</description>
      <pubDate>Tue, 27 Jun 2017 22:15:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/remove-repetitive-string-in-string/m-p/365355#M107764</guid>
      <dc:creator>exocore123</dc:creator>
      <dc:date>2017-06-27T22:15:31Z</dc:date>
    </item>
    <item>
      <title>Re: remove repetitive string in string</title>
      <link>https://community.splunk.com/t5/Splunk-Search/remove-repetitive-string-in-string/m-p/365356#M107765</link>
      <description>&lt;P&gt;Try this - &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults | eval myfield="asdw+wkas+asdw" 
| rename COMMENT as "The above creates test data"

| makemv delim="+" myfield 
| eval myfield=if(mvcount(myfield)&amp;lt;=1,myfield,"package(".mvjoin(mvdedup(myfield),"+").")")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;with resulting output...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;myfield
package(asdw+wkas)  
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Now, since you are not retaining the info on how many of each were originally there,  and since the field already had multiple values in it, you could forego the words "package()" around the altered field if you wanted.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makemv delim="+" myfield 
| eval myfield=if(mvcount(myfield)&amp;lt;=1,myfield,mvjoin(mvdedup(myfield),"+"))
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 27 Jun 2017 23:05:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/remove-repetitive-string-in-string/m-p/365356#M107765</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-06-27T23:05:15Z</dc:date>
    </item>
    <item>
      <title>Re: remove repetitive string in string</title>
      <link>https://community.splunk.com/t5/Splunk-Search/remove-repetitive-string-in-string/m-p/365357#M107766</link>
      <description>&lt;P&gt;Works perfectly, one comment, say I have a string3 I do not want to add after the makemv, say &lt;CODE&gt;string1+string2+string3&lt;/CODE&gt;, so after makemv it becomes &lt;CODE&gt;string1 string2 string3&lt;/CODE&gt;, say I want to mvjoin only &lt;STRONG&gt;string1&lt;/STRONG&gt; and &lt;STRONG&gt;string2&lt;/STRONG&gt;, is there a selective way to do this?&lt;/P&gt;</description>
      <pubDate>Tue, 27 Jun 2017 23:49:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/remove-repetitive-string-in-string/m-p/365357#M107766</guid>
      <dc:creator>exocore123</dc:creator>
      <dc:date>2017-06-27T23:49:08Z</dc:date>
    </item>
    <item>
      <title>Re: remove repetitive string in string</title>
      <link>https://community.splunk.com/t5/Splunk-Search/remove-repetitive-string-in-string/m-p/365358#M107767</link>
      <description>&lt;P&gt;There are two easy ways, depending on how many of string3 you have.   &lt;/P&gt;

&lt;P&gt;You can use &lt;CODE&gt;mvfilter&lt;/CODE&gt; ...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makemv delim="+" myfield 
| eval myfield=mvfilter(NOT match(myfield,"idonotwantthis|orthis"))
| eval myfield=if(mvcount(myfield)=1, myfield, "package(".mvjoin(mvdedup(myfield),"+").")")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If the list of wanted values is shorter than the list of unwanted ones, then remove the NOT and put your desired strings connected by the vertical &lt;CODE&gt;OR&lt;/CODE&gt; bars (&lt;CODE&gt;|&lt;/CODE&gt;). &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval myfield=mvfilter(match(myfield,"iwantthis|andthis|andthese"))
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Or you can also use &lt;CODE&gt;rex&lt;/CODE&gt; in &lt;CODE&gt;sed&lt;/CODE&gt; mode ...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makemv delim="+" myfield 
| eval myfield=if(mvcount(myfield)=1, myfield, "package(".mvjoin(mvdedup(myfield),"+").")")

| rename COMMENT as "The first sed gets rid of the undesired strings" 
| rex field=myfield mode=sed "s/idonotwantthis|orthis//g"

| rename COMMENT as  "The second sed gets rid of excess plusses at the front, middle or end of the string."
| rex field=myfield mode=sed "^\+|\+(?=\+)|\+$"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;There are also some more complex ways if you have a bunch of these undesired strings to check for.&lt;/P&gt;</description>
      <pubDate>Wed, 28 Jun 2017 01:42:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/remove-repetitive-string-in-string/m-p/365358#M107767</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-06-28T01:42:40Z</dc:date>
    </item>
    <item>
      <title>Re: remove repetitive string in string</title>
      <link>https://community.splunk.com/t5/Splunk-Search/remove-repetitive-string-in-string/m-p/365359#M107768</link>
      <description>&lt;P&gt;I think I get the idea, thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 28 Jun 2017 03:16:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/remove-repetitive-string-in-string/m-p/365359#M107768</guid>
      <dc:creator>exocore123</dc:creator>
      <dc:date>2017-06-28T03:16:05Z</dc:date>
    </item>
  </channel>
</rss>

