<?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: Confused with sed replace. Change 1,2,...,20,21,22    to   1,2,...,20,###,22 in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Confused-with-sed-replace-Change-1-2-20-21-22-to-1-2-20-22/m-p/142287#M39462</link>
    <description>&lt;P&gt;Sed works like this: Take what was matched by the first part out and replace by the second part... so all your 21 strings are being removed. You can avoid that like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;s/(?i)((?:[^,]*,){21})([^,]+,)/\1###,/
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;That captures the matched strings and retains them before the ###. Here's a dummy query to test:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats count | eval string = "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z" | rex field=string mode=sed "s/(?i)((?:[^,]*,){21})([^,]+,)/\1###,/"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 15 Jul 2014 08:14:03 GMT</pubDate>
    <dc:creator>martin_mueller</dc:creator>
    <dc:date>2014-07-15T08:14:03Z</dc:date>
    <item>
      <title>Confused with sed replace. Change 1,2,...,20,21,22    to   1,2,...,20,###,22</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Confused-with-sed-replace-Change-1-2-20-21-22-to-1-2-20-22/m-p/142286#M39461</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;I try to test sed expressions in search app for futher proper filtering of incoming data with SEDCMD.&lt;BR /&gt;
Let 1 have a strings [0-9a-zA-Z]* delimited by commas. There can be no any string between commas.&lt;/P&gt;

&lt;P&gt;i.e. 1,a,B,,D,5&lt;/P&gt;

&lt;P&gt;I'm trying to build regex to change 21-th pattern occurence in the string to some fixed chars (#)&lt;/P&gt;

&lt;P&gt;Splunk IFX gives me that perfect extraction regex&lt;/P&gt;

&lt;BLOCKQUOTE&gt;
&lt;P&gt;(?i)^(?:[^,]*,){21}(?P&lt;FIELDNAME&gt;[^,]+)&lt;/FIELDNAME&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;

&lt;P&gt;I tried to transform it to sed replace&lt;/P&gt;

&lt;BLOCKQUOTE&gt;
&lt;P&gt;s/(?i)(?:[^,]*,){21}([^,]+,)/###,/&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;

&lt;P&gt;It gives me all string wiped from start to 22-th pattern occurence&lt;/P&gt;

&lt;BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;###,22-th occurence,24,25&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;

&lt;P&gt;What am I doing wrong?&lt;/P&gt;</description>
      <pubDate>Tue, 15 Jul 2014 07:54:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Confused-with-sed-replace-Change-1-2-20-21-22-to-1-2-20-22/m-p/142286#M39461</guid>
      <dc:creator>ejpulsar</dc:creator>
      <dc:date>2014-07-15T07:54:57Z</dc:date>
    </item>
    <item>
      <title>Re: Confused with sed replace. Change 1,2,...,20,21,22    to   1,2,...,20,###,22</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Confused-with-sed-replace-Change-1-2-20-21-22-to-1-2-20-22/m-p/142287#M39462</link>
      <description>&lt;P&gt;Sed works like this: Take what was matched by the first part out and replace by the second part... so all your 21 strings are being removed. You can avoid that like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;s/(?i)((?:[^,]*,){21})([^,]+,)/\1###,/
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;That captures the matched strings and retains them before the ###. Here's a dummy query to test:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats count | eval string = "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z" | rex field=string mode=sed "s/(?i)((?:[^,]*,){21})([^,]+,)/\1###,/"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 15 Jul 2014 08:14:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Confused-with-sed-replace-Change-1-2-20-21-22-to-1-2-20-22/m-p/142287#M39462</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2014-07-15T08:14:03Z</dc:date>
    </item>
    <item>
      <title>Re: Confused with sed replace. Change 1,2,...,20,21,22    to   1,2,...,20,###,22</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Confused-with-sed-replace-Change-1-2-20-21-22-to-1-2-20-22/m-p/142288#M39463</link>
      <description>&lt;P&gt;You are awesome right!&lt;BR /&gt;
Thank you!&lt;/P&gt;</description>
      <pubDate>Tue, 15 Jul 2014 08:21:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Confused-with-sed-replace-Change-1-2-20-21-22-to-1-2-20-22/m-p/142288#M39463</guid>
      <dc:creator>ejpulsar</dc:creator>
      <dc:date>2014-07-15T08:21:03Z</dc:date>
    </item>
  </channel>
</rss>

