<?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 replace an alphanumeric string in a field? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-replace-an-alphanumeric-string-in-a-field/m-p/434467#M169129</link>
    <description>&lt;P&gt;@saibalabadra, please try to pipe the following eval and stats to your existing search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;yourCurrentSearch&amp;gt;
    | eval url_pattern=case(match(url,"abc\/xyz\/def\/uvw\/.*\/.*\/rst"),"abc/xyz/def/uvw/*/*/rst",match(url,"abc\/xyz\/.*\/uvw"),"abc/xyz/*/uvw")
    | stats sum(count) as Count by url_pattern
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Following is a run anywhere search based on sample data provided in the question&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval data="abc/xyz/1000/uvw 1;abc/xyz/2000/uvw 1;abc/xyz/3000/uvw 1;abc/xyz/def/uvw/1234/a1b2c3d4/rst 1;abc/xyz/def/uvw/5678/e5f6g7h8/rst 1"
| makemv data delim=";"
| mvexpand data
| makemv data delim=" "
| eval url=mvindex(data,0), count=mvindex(data,1)
| fields - _time data
| eval url_pattern=case(match(url,"abc\/xyz\/def\/uvw\/.*\/.*\/rst"),"abc/xyz/def/uvw/*/*/rst",match(url,"abc\/xyz\/.*\/uvw"),"abc/xyz/*/uvw")
| stats sum(count) as Count by url_pattern
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 02 Jun 2018 11:13:29 GMT</pubDate>
    <dc:creator>niketn</dc:creator>
    <dc:date>2018-06-02T11:13:29Z</dc:date>
    <item>
      <title>How to replace an alphanumeric string in a field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-replace-an-alphanumeric-string-in-a-field/m-p/434464#M169126</link>
      <description>&lt;P&gt;I have query to count the URIs but in some places there are dynamic values so I am trying to replace dynamic values with a character like '*' so that same URI pattern will be considered as one value and list the total count irrespective of dynamic value. I tried below query but it is replacing only numbers.&lt;/P&gt;

&lt;P&gt;Ex:&lt;/P&gt;

&lt;P&gt;Query: ....|stats count by URI&lt;/P&gt;

&lt;P&gt;Actual Result:&lt;/P&gt;

&lt;P&gt;URI                         Count&lt;BR /&gt;
abc/xyz/1000/uvw         1&lt;BR /&gt;
abc/xyz/2000/uvw         1 &lt;BR /&gt;
abc/xyz/3000/uvw         1 &lt;BR /&gt;
abc/xyz/def/uvw/1234/a1b2c3d4/rst        1&lt;BR /&gt;
abc/xyz/def/uvw/5678/e5f6g7h8/rst         1&lt;/P&gt;

&lt;P&gt;Expected Result:&lt;/P&gt;

&lt;P&gt;URI                                      Count&lt;BR /&gt;
abc/xyz/*/uvw                     3&lt;BR /&gt;
abc/xyz/def/uvw/*/*/rst    2&lt;/P&gt;</description>
      <pubDate>Fri, 01 Jun 2018 23:10:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-replace-an-alphanumeric-string-in-a-field/m-p/434464#M169126</guid>
      <dc:creator>saibalabadra</dc:creator>
      <dc:date>2018-06-01T23:10:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to replace an alphanumeric string in a field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-replace-an-alphanumeric-string-in-a-field/m-p/434465#M169127</link>
      <description>&lt;P&gt;Are those the only 2 specific patterns you need to handle, or are there more variations?&lt;/P&gt;</description>
      <pubDate>Sat, 02 Jun 2018 01:21:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-replace-an-alphanumeric-string-in-a-field/m-p/434465#M169127</guid>
      <dc:creator>FrankVl</dc:creator>
      <dc:date>2018-06-02T01:21:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to replace an alphanumeric string in a field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-replace-an-alphanumeric-string-in-a-field/m-p/434466#M169128</link>
      <description>&lt;P&gt;There are more variations but they are similar except that the position of dynamic values would very. I tried below rex command but it is replacing numbers only, if I update expression to consider alphanumeric then it is replacing all characters in the field and returning just slashes and asterisks.&lt;/P&gt;

&lt;P&gt;|rex field=URI mode=sed "/s[0-9\s\t\n\v]+ | {2,} /* /g"&lt;BR /&gt;
|stats count by URI&lt;/P&gt;

&lt;P&gt;Result:&lt;/P&gt;

&lt;P&gt;URI                                                     Count&lt;BR /&gt;
abc/xyz/&lt;EM&gt;/uvw                                  3&lt;BR /&gt;
abc/xyz/def/uvw/&lt;/EM&gt;/a*b*c*d*/rst  1&lt;BR /&gt;
abc/xyz/def/uvw/&lt;EM&gt;/e*f*g*h&lt;/EM&gt;/rst   1&lt;/P&gt;

&lt;P&gt;|rex field=URI mode=sed "/s[a-zA-Z0-9\s\t\n\v]+ | {2,} /* /g"&lt;BR /&gt;
|stats count by URI&lt;/P&gt;

&lt;P&gt;URI                            Count&lt;BR /&gt;
&lt;EM&gt;/&lt;/EM&gt;/&lt;EM&gt;/&lt;/EM&gt;                       3&lt;BR /&gt;
&lt;EM&gt;/&lt;/EM&gt;/&lt;EM&gt;/&lt;/EM&gt;/&lt;EM&gt;/&lt;/EM&gt;/*            2&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 19:48:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-replace-an-alphanumeric-string-in-a-field/m-p/434466#M169128</guid>
      <dc:creator>saibalabadra</dc:creator>
      <dc:date>2020-09-29T19:48:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to replace an alphanumeric string in a field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-replace-an-alphanumeric-string-in-a-field/m-p/434467#M169129</link>
      <description>&lt;P&gt;@saibalabadra, please try to pipe the following eval and stats to your existing search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;yourCurrentSearch&amp;gt;
    | eval url_pattern=case(match(url,"abc\/xyz\/def\/uvw\/.*\/.*\/rst"),"abc/xyz/def/uvw/*/*/rst",match(url,"abc\/xyz\/.*\/uvw"),"abc/xyz/*/uvw")
    | stats sum(count) as Count by url_pattern
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Following is a run anywhere search based on sample data provided in the question&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval data="abc/xyz/1000/uvw 1;abc/xyz/2000/uvw 1;abc/xyz/3000/uvw 1;abc/xyz/def/uvw/1234/a1b2c3d4/rst 1;abc/xyz/def/uvw/5678/e5f6g7h8/rst 1"
| makemv data delim=";"
| mvexpand data
| makemv data delim=" "
| eval url=mvindex(data,0), count=mvindex(data,1)
| fields - _time data
| eval url_pattern=case(match(url,"abc\/xyz\/def\/uvw\/.*\/.*\/rst"),"abc/xyz/def/uvw/*/*/rst",match(url,"abc\/xyz\/.*\/uvw"),"abc/xyz/*/uvw")
| stats sum(count) as Count by url_pattern
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 02 Jun 2018 11:13:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-replace-an-alphanumeric-string-in-a-field/m-p/434467#M169129</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2018-06-02T11:13:29Z</dc:date>
    </item>
  </channel>
</rss>

