<?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 easily replace a character in a token value ? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-easily-replace-a-character-in-a-token-value/m-p/247799#M73928</link>
    <description>&lt;P&gt;That was just me wanting to display all the different field values for debugging purposes in my test query. Feel free to get rid of it:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| gentimes start=-1
| eval myToken = replace($token$, "\(", "\\\\\28") 
| eval myToken = replace(myToken, "\)", "\\\\\29")
| rex field=myToken "^\\\\\\\\28(?&amp;lt;myToken&amp;gt;.+)\\\\\\\\29$"
| eval myToken = "(" . myToken . ")"
| map search="| ldapsearch domain=mydoman search=\"$$myToken$$\""
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 26 Jan 2016 16:09:44 GMT</pubDate>
    <dc:creator>javiergn</dc:creator>
    <dc:date>2016-01-26T16:09:44Z</dc:date>
    <item>
      <title>How to easily replace a character in a token value ?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-easily-replace-a-character-in-a-token-value/m-p/247787#M73916</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;

&lt;P&gt;I have a token "user" representing the name of a user. This name can contain "(" or ")". When I am using this token to execute a LDAP search, I get an error because it cannot contains brackets. The solution is to replace &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; ( by \28
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;and&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;) by \29.
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I tried it without using the token, and it works:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; | ldapsearch domain=mydoman search="(CN=John Doe \\28test\\29)"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Unfortunately, I am using a dashboard to automatically complete this username. I need to replace the brackets by \28 and \29.&lt;BR /&gt;
Is there a quick way to do this?&lt;/P&gt;

&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Tue, 26 Jan 2016 13:29:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-easily-replace-a-character-in-a-token-value/m-p/247787#M73916</guid>
      <dc:creator>ctaf</dc:creator>
      <dc:date>2016-01-26T13:29:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to easily replace a character in a token value ?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-easily-replace-a-character-in-a-token-value/m-p/247788#M73917</link>
      <description>&lt;P&gt;Use eval replace() to reformat the token value&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval foo=replace($token$),"\(","\28") |eval foo=replace(foo,"\)","\29") |  ldapsearch domain=mydomain search=foo
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;See replace() in &lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Commonevalfunctions"&gt;http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Commonevalfunctions&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Jan 2016 13:46:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-easily-replace-a-character-in-a-token-value/m-p/247788#M73917</guid>
      <dc:creator>jplumsdaine22</dc:creator>
      <dc:date>2016-01-26T13:46:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to easily replace a character in a token value ?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-easily-replace-a-character-in-a-token-value/m-p/247789#M73918</link>
      <description>&lt;P&gt;This is something I tried but if I do that, "foo" won't be evaluated. So the LDAP Search string is just the string "foo".&lt;/P&gt;</description>
      <pubDate>Tue, 26 Jan 2016 13:56:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-easily-replace-a-character-in-a-token-value/m-p/247789#M73918</guid>
      <dc:creator>ctaf</dc:creator>
      <dc:date>2016-01-26T13:56:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to easily replace a character in a token value ?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-easily-replace-a-character-in-a-token-value/m-p/247790#M73919</link>
      <description>&lt;P&gt;This would be my approach (simply replace myToken with $yourtoken$ and it should work):&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval myToken = "(CN=John Doe (test))"
| rex field=myToken mode=sed "s/(^\(.+)(\()/\\1\\\\\28/g"
| rex field=myToken mode=sed "s/([^\)]+)(\))(.*\)$)/\\1\\\\\29\\3/g"

output: (CN=John Doe \\28test\\29) 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Alternatively, this one is a bit more robust as it should replace ALL your parenthesis and then fix your LDAP string by appending opening and closing ones:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval myToken = "(CN=John Doe (test))"
| eval myToken = replace(myToken, "\(", "\\\\\28") 
| eval myToken = replace(myToken, "\)", "\\\\\29")
| rex field=myToken "^\\\\\\\\28(?&amp;lt;tempToken&amp;gt;.+)\\\\\\\\29$"
| eval myToken = "(" . tempToken . ")"
| fields - tempToken

output: (CN=John Doe \\28test\\29) 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Alternative number 3 as suggested below:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| gentimes start=-1
| eval myToken = replace($token$, "\(", "\\\\\28") 
| eval myToken = replace(myToken, "\)", "\\\\\29")
| rex field=myToken "^\\\\\\\\28(?&amp;lt;tempToken&amp;gt;.+)\\\\\\\\29$"
| eval myToken = "(" . tempToken . ")"
| fields - tempToken
| map search="| ldapsearch domain=mydoman search=\"$$myToken$$\""
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Let me know if that helps.&lt;/P&gt;

&lt;P&gt;Thanks,&lt;BR /&gt;
Javier&lt;/P&gt;</description>
      <pubDate>Tue, 26 Jan 2016 14:08:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-easily-replace-a-character-in-a-token-value/m-p/247790#M73919</guid>
      <dc:creator>javiergn</dc:creator>
      <dc:date>2016-01-26T14:08:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to easily replace a character in a token value ?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-easily-replace-a-character-in-a-token-value/m-p/247791#M73920</link>
      <description>&lt;P&gt;The problem is that this solution uses the token value in the "field=XXX" option.&lt;/P&gt;

&lt;P&gt;| rex field=John Doe (test) mode=sed "s/(^(.+)(()/\1\\\28/g"&lt;BR /&gt;
 | rex field=John Doe (test) mode=sed "s/([^)]+)())(.*)$)/\1\\\29\3/g"&lt;/P&gt;</description>
      <pubDate>Tue, 26 Jan 2016 14:58:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-easily-replace-a-character-in-a-token-value/m-p/247791#M73920</guid>
      <dc:creator>ctaf</dc:creator>
      <dc:date>2016-01-26T14:58:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to easily replace a character in a token value ?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-easily-replace-a-character-in-a-token-value/m-p/247792#M73921</link>
      <description>&lt;P&gt;I see what you mean. Sorry i don't have an easy way to test this but what about the following using the map command?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| gentimes start=-1
| eval myToken = replace($token$, "\(", "\\\\\28") 
| eval myToken = replace(myToken, "\)", "\\\\\29")
| rex field=myToken "^\\\\\\\\28(?&amp;lt;tempToken&amp;gt;.+)\\\\\\\\29$"
| eval myToken = "(" . tempToken . ")"
| fields - tempToken
| map search="| ldapsearch domain=mydoman search=\"$$myToken$$\""
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;EDIT: fixed query above as there was a typo because of the copy and paste&lt;BR /&gt;
EDIT2: adding double $ to myToken&lt;/P&gt;</description>
      <pubDate>Tue, 26 Jan 2016 15:06:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-easily-replace-a-character-in-a-token-value/m-p/247792#M73921</guid>
      <dc:creator>javiergn</dc:creator>
      <dc:date>2016-01-26T15:06:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to easily replace a character in a token value ?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-easily-replace-a-character-in-a-token-value/m-p/247793#M73922</link>
      <description>&lt;P&gt;This solution give me a "The search is waiting for input" message on my dashboard. I guess it is because "$myToken$" is not  set.&lt;/P&gt;

&lt;P&gt;EDIT: I think I missed your "edit". What did you change?&lt;/P&gt;</description>
      <pubDate>Tue, 26 Jan 2016 15:29:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-easily-replace-a-character-in-a-token-value/m-p/247793#M73922</guid>
      <dc:creator>ctaf</dc:creator>
      <dc:date>2016-01-26T15:29:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to easily replace a character in a token value ?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-easily-replace-a-character-in-a-token-value/m-p/247794#M73923</link>
      <description>&lt;P&gt;Use double $ sign for mytoken.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Jan 2016 15:32:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-easily-replace-a-character-in-a-token-value/m-p/247794#M73923</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2016-01-26T15:32:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to easily replace a character in a token value ?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-easily-replace-a-character-in-a-token-value/m-p/247795#M73924</link>
      <description>&lt;P&gt;That's what I did: | ldapsearch domain=mydomain search=\"(CN=$myToken$)\"&lt;/P&gt;</description>
      <pubDate>Tue, 26 Jan 2016 15:38:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-easily-replace-a-character-in-a-token-value/m-p/247795#M73924</guid>
      <dc:creator>ctaf</dc:creator>
      <dc:date>2016-01-26T15:38:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to easily replace a character in a token value ?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-easily-replace-a-character-in-a-token-value/m-p/247796#M73925</link>
      <description>&lt;P&gt;Use map as well then: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval foo=replace($token$),"\(","\28") |eval foo=replace(foo,"\)","\29") | map search="| ldapsearch domain=mydoman search=$foo$"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 26 Jan 2016 15:39:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-easily-replace-a-character-in-a-token-value/m-p/247796#M73925</guid>
      <dc:creator>jplumsdaine22</dc:creator>
      <dc:date>2016-01-26T15:39:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to easily replace a character in a token value ?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-easily-replace-a-character-in-a-token-value/m-p/247797#M73926</link>
      <description>&lt;P&gt;No like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; | ldapsearch domain=mydomain search="(CN=$$myToken$$)"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 26 Jan 2016 15:43:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-easily-replace-a-character-in-a-token-value/m-p/247797#M73926</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2016-01-26T15:43:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to easily replace a character in a token value ?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-easily-replace-a-character-in-a-token-value/m-p/247798#M73927</link>
      <description>&lt;P&gt;Oh OK. We're progressing, but it still doesn't work. I am not sure what is "tempToken" for as it is empty and the last "eval myToken" makes "myToken" empty too... Very strange.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Jan 2016 16:03:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-easily-replace-a-character-in-a-token-value/m-p/247798#M73927</guid>
      <dc:creator>ctaf</dc:creator>
      <dc:date>2016-01-26T16:03:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to easily replace a character in a token value ?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-easily-replace-a-character-in-a-token-value/m-p/247799#M73928</link>
      <description>&lt;P&gt;That was just me wanting to display all the different field values for debugging purposes in my test query. Feel free to get rid of it:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| gentimes start=-1
| eval myToken = replace($token$, "\(", "\\\\\28") 
| eval myToken = replace(myToken, "\)", "\\\\\29")
| rex field=myToken "^\\\\\\\\28(?&amp;lt;myToken&amp;gt;.+)\\\\\\\\29$"
| eval myToken = "(" . myToken . ")"
| map search="| ldapsearch domain=mydoman search=\"$$myToken$$\""
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 26 Jan 2016 16:09:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-easily-replace-a-character-in-a-token-value/m-p/247799#M73928</guid>
      <dc:creator>javiergn</dc:creator>
      <dc:date>2016-01-26T16:09:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to easily replace a character in a token value ?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-easily-replace-a-character-in-a-token-value/m-p/247800#M73929</link>
      <description>&lt;P&gt;Yeah ! I managed to make it work:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| gentimes start=-1 | eval myToken = replace("$user$", "\(", "\\28")   | eval myToken = replace(myToken, "\)", "\\29")  | map search="| ldapsearch domain=mydomain search=\"(CN=$$myToken$$)\""
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Splunk was showing only 2 backslash in when you set up 5 of them but when using it in the LDAP search, it needed only 2...&lt;/P&gt;

&lt;P&gt;I removed the rex function and the last eval too.&lt;/P&gt;

&lt;P&gt;I have one more question: What is "gentimes" for ?&lt;/P&gt;</description>
      <pubDate>Tue, 26 Jan 2016 16:26:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-easily-replace-a-character-in-a-token-value/m-p/247800#M73929</guid>
      <dc:creator>ctaf</dc:creator>
      <dc:date>2016-01-26T16:26:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to easily replace a character in a token value ?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-easily-replace-a-character-in-a-token-value/m-p/247801#M73930</link>
      <description>&lt;P&gt;Thank you !&lt;/P&gt;</description>
      <pubDate>Tue, 26 Jan 2016 16:26:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-easily-replace-a-character-in-a-token-value/m-p/247801#M73930</guid>
      <dc:creator>ctaf</dc:creator>
      <dc:date>2016-01-26T16:26:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to easily replace a character in a token value ?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-easily-replace-a-character-in-a-token-value/m-p/247802#M73931</link>
      <description>&lt;P&gt;That's just for my example to be able to use non search commands when you don't really have a search. You can use "| stats count" too.&lt;/P&gt;

&lt;P&gt;It is quite useful when testing things as otherwise you need to start your search with an actual search or input type command.&lt;/P&gt;

&lt;P&gt;There are other uses for gentimes of course. See the &lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Gentimes"&gt;doc&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Jan 2016 16:29:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-easily-replace-a-character-in-a-token-value/m-p/247802#M73931</guid>
      <dc:creator>javiergn</dc:creator>
      <dc:date>2016-01-26T16:29:09Z</dc:date>
    </item>
  </channel>
</rss>

