<?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 use sed to replace a string with value from another variable? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-sed-to-replace-a-string-with-value-from-another/m-p/268780#M80837</link>
    <description>&lt;P&gt;That would create a variable named scheduleendtime and it would hold value of difference.&lt;BR /&gt;
How can i insert that value in splunk output?&lt;/P&gt;</description>
    <pubDate>Fri, 21 Oct 2016 22:15:06 GMT</pubDate>
    <dc:creator>pdahal</dc:creator>
    <dc:date>2016-10-21T22:15:06Z</dc:date>
    <item>
      <title>How to use sed to replace a string with value from another variable?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-sed-to-replace-a-string-with-value-from-another/m-p/268778#M80835</link>
      <description>&lt;P&gt;I want to replace &lt;CODE&gt;scheduleendtime=...&amp;amp;&lt;/CODE&gt; with &lt;CODE&gt;scheduleendtime=valueOf(difference)&lt;/CODE&gt; in Splunk output. &lt;/P&gt;

&lt;P&gt;In Linux shell, this can be done using &lt;CODE&gt;sed s/scheduleendtime=[^&amp;amp;]*/scheduleendtime=$difference/&lt;/CODE&gt;. When I try using same command in splunk, I fail horribly. Splunk doesn't do variable replacement in sed rather every occurrence of "scheduleendtime=[^&amp;amp;]*" is replaced with "scheduleendtime=$difference" exact string.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | eval difference = case(schedule_time_diff &amp;lt;= 4200,"&amp;lt;_1_hour", schedule_time_diff &amp;lt; 28800, "&amp;lt;_8_hours", schedule_time_diff &amp;lt; 172800, " &amp;lt;_2_days") | rex mode=sed s/scheduleendtime=[^&amp;amp;]*/scheduleendtime=$difference/
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I used sed because I am comfortable with it. If you think another command works better in this scenario, please let me know.&lt;/P&gt;</description>
      <pubDate>Fri, 21 Oct 2016 21:47:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-sed-to-replace-a-string-with-value-from-another/m-p/268778#M80835</guid>
      <dc:creator>pdahal</dc:creator>
      <dc:date>2016-10-21T21:47:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to use sed to replace a string with value from another variable?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-sed-to-replace-a-string-with-value-from-another/m-p/268779#M80836</link>
      <description>&lt;P&gt;Why not just set scheduleendtime&lt;CODE&gt;to&lt;/CODE&gt;difference&lt;CODE&gt;using&lt;/CODE&gt;eval&lt;CODE&gt;...&lt;/CODE&gt;eval scheduleendtime=difference`.?&lt;/P&gt;</description>
      <pubDate>Fri, 21 Oct 2016 22:10:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-sed-to-replace-a-string-with-value-from-another/m-p/268779#M80836</guid>
      <dc:creator>sundareshr</dc:creator>
      <dc:date>2016-10-21T22:10:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to use sed to replace a string with value from another variable?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-sed-to-replace-a-string-with-value-from-another/m-p/268780#M80837</link>
      <description>&lt;P&gt;That would create a variable named scheduleendtime and it would hold value of difference.&lt;BR /&gt;
How can i insert that value in splunk output?&lt;/P&gt;</description>
      <pubDate>Fri, 21 Oct 2016 22:15:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-sed-to-replace-a-string-with-value-from-another/m-p/268780#M80837</guid>
      <dc:creator>pdahal</dc:creator>
      <dc:date>2016-10-21T22:15:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to use sed to replace a string with value from another variable?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-sed-to-replace-a-string-with-value-from-another/m-p/268781#M80838</link>
      <description>&lt;P&gt;How about &lt;CODE&gt;replace()&lt;/CODE&gt; function. Here's a simple example on how you might be able to use it&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval searchtime="sometext&amp;amp;somemoretext" 
| eval difference="123456" 
| eval searchtime=replace(searchtime, "^([^&amp;amp;]+)", difference) 
| table searchtime difference
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 21 Oct 2016 22:35:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-sed-to-replace-a-string-with-value-from-another/m-p/268781#M80838</guid>
      <dc:creator>sundareshr</dc:creator>
      <dc:date>2016-10-21T22:35:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to use sed to replace a string with value from another variable?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-sed-to-replace-a-string-with-value-from-another/m-p/268782#M80839</link>
      <description>&lt;P&gt;Based on your comment above:&lt;BR /&gt;
&lt;STRONG&gt;How can i insert that value in splunk output?&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;Here is how you can get the output back in raw and might not need sed at all:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | eval difference = case(schedule_time_diff &amp;lt;= 4200,"&amp;lt;_1_hour", schedule_time_diff &amp;lt; 28800, "&amp;lt;_8_hours", schedule_time_diff &amp;lt; 172800, " &amp;lt;_2_days") 
| rex "^(?&amp;lt;headOfText&amp;gt;.*scheduleendtime=)[^&amp;amp;]*(?&amp;lt;tailOfText&amp;gt;\&amp;amp;.*)"
| eval _raw=headOfText.difference.tailOfText
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 23 Oct 2016 02:16:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-sed-to-replace-a-string-with-value-from-another/m-p/268782#M80839</guid>
      <dc:creator>gokadroid</dc:creator>
      <dc:date>2016-10-23T02:16:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to use sed to replace a string with value from another variable?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-sed-to-replace-a-string-with-value-from-another/m-p/268783#M80840</link>
      <description>&lt;P&gt;Thank you @gokadroid. This works like a charm.&lt;BR /&gt;
BTW, you missed a quote at the end of 3rd line.&lt;/P&gt;</description>
      <pubDate>Mon, 24 Oct 2016 23:45:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-sed-to-replace-a-string-with-value-from-another/m-p/268783#M80840</guid>
      <dc:creator>pdahal</dc:creator>
      <dc:date>2016-10-24T23:45:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to use sed to replace a string with value from another variable?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-sed-to-replace-a-string-with-value-from-another/m-p/268784#M80841</link>
      <description>&lt;P&gt;damn...I need to go to get my eyes checked up.. thanks man...editing the rex piece. An upvote will help a lot too.&lt;/P&gt;</description>
      <pubDate>Mon, 24 Oct 2016 23:47:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-sed-to-replace-a-string-with-value-from-another/m-p/268784#M80841</guid>
      <dc:creator>gokadroid</dc:creator>
      <dc:date>2016-10-24T23:47:51Z</dc:date>
    </item>
  </channel>
</rss>

