<?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 Replace random string in a field in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Replace-random-string-in-a-field/m-p/423816#M121616</link>
    <description>&lt;P&gt;Hi team,&lt;/P&gt;

&lt;P&gt;I've 1 field named - 'URI' coming in micro service log dump.&lt;/P&gt;

&lt;P&gt;Example Values of URI field is like below - &lt;/P&gt;

&lt;P&gt;/mobile/login&lt;BR /&gt;
/desktop/login&lt;BR /&gt;
/account/100123445/details&lt;BR /&gt;
/account/100123999/details&lt;BR /&gt;
/public/account/XYZAASWDDSSSS/transactions&lt;BR /&gt;
/public/account/XYZQWERTS/transactions&lt;/P&gt;

&lt;P&gt;Now I'm just trying to see successful or failure transactions list sorted by the URI.&lt;/P&gt;

&lt;P&gt;My example query - &lt;BR /&gt;
index=mslogs "successful"|stats count by URI&lt;/P&gt;

&lt;P&gt;Now the problem is, the result is coming as - &lt;BR /&gt;
URI Count&lt;BR /&gt;
/mobile/login 50&lt;BR /&gt;
/desktop/login 50&lt;BR /&gt;
/account/100123445/details 1&lt;BR /&gt;
/account/100123999/details 1&lt;BR /&gt;
/public/account/XYZAASWDDSSSS/transactions 1&lt;BR /&gt;
/public/account/XYZQWERTS/transactions 1&lt;/P&gt;

&lt;P&gt;Obviously, I need this to show like - &lt;/P&gt;

&lt;P&gt;/mobile/login 50&lt;BR /&gt;
/desktop/login 50&lt;BR /&gt;
/account/&lt;EM&gt;/details 2&lt;BR /&gt;
/public/account/&lt;/EM&gt;/transactions 2&lt;/P&gt;

&lt;P&gt;Basically I want to remove the random string part in the 'URI' field. Different URI has different random parts and those random parts are present differently in the URI. I'm willing to write regex to handle all the scenario in URI, but I want to replace them with '*' so that if I do a 'stats' or timechart, single URI.&lt;/P&gt;

&lt;P&gt;Please suggest.&lt;/P&gt;</description>
    <pubDate>Thu, 01 Aug 2019 09:51:05 GMT</pubDate>
    <dc:creator>pjtbasu</dc:creator>
    <dc:date>2019-08-01T09:51:05Z</dc:date>
    <item>
      <title>Replace random string in a field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Replace-random-string-in-a-field/m-p/423816#M121616</link>
      <description>&lt;P&gt;Hi team,&lt;/P&gt;

&lt;P&gt;I've 1 field named - 'URI' coming in micro service log dump.&lt;/P&gt;

&lt;P&gt;Example Values of URI field is like below - &lt;/P&gt;

&lt;P&gt;/mobile/login&lt;BR /&gt;
/desktop/login&lt;BR /&gt;
/account/100123445/details&lt;BR /&gt;
/account/100123999/details&lt;BR /&gt;
/public/account/XYZAASWDDSSSS/transactions&lt;BR /&gt;
/public/account/XYZQWERTS/transactions&lt;/P&gt;

&lt;P&gt;Now I'm just trying to see successful or failure transactions list sorted by the URI.&lt;/P&gt;

&lt;P&gt;My example query - &lt;BR /&gt;
index=mslogs "successful"|stats count by URI&lt;/P&gt;

&lt;P&gt;Now the problem is, the result is coming as - &lt;BR /&gt;
URI Count&lt;BR /&gt;
/mobile/login 50&lt;BR /&gt;
/desktop/login 50&lt;BR /&gt;
/account/100123445/details 1&lt;BR /&gt;
/account/100123999/details 1&lt;BR /&gt;
/public/account/XYZAASWDDSSSS/transactions 1&lt;BR /&gt;
/public/account/XYZQWERTS/transactions 1&lt;/P&gt;

&lt;P&gt;Obviously, I need this to show like - &lt;/P&gt;

&lt;P&gt;/mobile/login 50&lt;BR /&gt;
/desktop/login 50&lt;BR /&gt;
/account/&lt;EM&gt;/details 2&lt;BR /&gt;
/public/account/&lt;/EM&gt;/transactions 2&lt;/P&gt;

&lt;P&gt;Basically I want to remove the random string part in the 'URI' field. Different URI has different random parts and those random parts are present differently in the URI. I'm willing to write regex to handle all the scenario in URI, but I want to replace them with '*' so that if I do a 'stats' or timechart, single URI.&lt;/P&gt;

&lt;P&gt;Please suggest.&lt;/P&gt;</description>
      <pubDate>Thu, 01 Aug 2019 09:51:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Replace-random-string-in-a-field/m-p/423816#M121616</guid>
      <dc:creator>pjtbasu</dc:creator>
      <dc:date>2019-08-01T09:51:05Z</dc:date>
    </item>
    <item>
      <title>Re: Replace random string in a field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Replace-random-string-in-a-field/m-p/423817#M121617</link>
      <description>&lt;P&gt;Greetings @pjtbasu,&lt;/P&gt;

&lt;P&gt;As you said, you'll want to regex them out. The beginning of the regex replace command for all of them would be &lt;CODE&gt;| eval URI = replace(URI,&lt;/CODE&gt;. followed by:&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;/account/#####/details&lt;/CODE&gt; = &lt;CODE&gt;"(/account)/[^/]+(/details)", "\1\2")&lt;/CODE&gt;&lt;BR /&gt;
&lt;CODE&gt;/public/account/#####/transactions&lt;/CODE&gt; = &lt;CODE&gt;"(/public/account)/[^/]+(/transactions)", "\1\2")&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;Here's a run-anywhere search for your sample data:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval URI="/account/100123445/details"
| append [ | makeresults | eval URI="/public/account/XYZAASWDDSSSS/transactions" ]
| eval URI = replace(URI, "(/account)/[^/]+(/details)",             "\1\2")
| eval URI = replace(URI, "(/public/account)/[^/]+(/transactions)", "\1\2")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 01 Aug 2019 14:22:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Replace-random-string-in-a-field/m-p/423817#M121617</guid>
      <dc:creator>jacobpevans</dc:creator>
      <dc:date>2019-08-01T14:22:39Z</dc:date>
    </item>
  </channel>
</rss>

