<?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 escape a parentheses in sed rex command ? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-escape-a-parentheses-in-sed-rex-command/m-p/304330#M91516</link>
    <description>&lt;P&gt;yes this is the answer haha.. So regexes are only used in the first part of the sed, not both parts ! Thank you!&lt;/P&gt;</description>
    <pubDate>Wed, 29 Mar 2017 12:14:15 GMT</pubDate>
    <dc:creator>DavidHourani</dc:creator>
    <dc:date>2017-03-29T12:14:15Z</dc:date>
    <item>
      <title>How to escape a parentheses in sed rex command ?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-escape-a-parentheses-in-sed-rex-command/m-p/304328#M91514</link>
      <description>&lt;P&gt;Hello dearest Splunkers,&lt;/P&gt;

&lt;P&gt;I am trying to convert "(A=hi) OR (B=bye)" to "(A=hi) NOT (B=bye)" using sed. So far I have the following command:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;...| rex mode=sed field=search "s/\sOR\s\(/\sNOT\s\(/g"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This gives me the following error, since apparently the backslash isnt enough to escape the parentheses:&lt;/P&gt;

&lt;P&gt;&lt;EM&gt;Error in 'rex' command: Regex: missing closing parenthesis&lt;/EM&gt; &lt;/P&gt;

&lt;P&gt;Can anyone help me out understanding how I can improve the regex or what I should use as an escape character instead of the backslash ? &lt;/P&gt;

&lt;P&gt;Thank you.&lt;/P&gt;

&lt;P&gt;Regards,&lt;BR /&gt;
David &lt;/P&gt;</description>
      <pubDate>Wed, 29 Mar 2017 11:40:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-escape-a-parentheses-in-sed-rex-command/m-p/304328#M91514</guid>
      <dc:creator>DavidHourani</dc:creator>
      <dc:date>2017-03-29T11:40:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to escape a parentheses in sed rex command ?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-escape-a-parentheses-in-sed-rex-command/m-p/304329#M91515</link>
      <description>&lt;P&gt;Try&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;...| rex field=search mode=sed "s/ OR / NOT /g"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;You don't need to use any special space characters unless you really need to (i.e. they may be tabs or something).  It doesn't feel like you do so you can simplify.&lt;/P&gt;

&lt;P&gt;And, if you DID need to include the parenthesis, you only need to escape them in the first half of the sed command (the match part). &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | rex field=orig_field mode=sed "s/\) OR \(/) NOT (/g"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I know it looks funny but it does work.  For clarity, the first half (matching part) is &lt;CODE&gt;\) OR \(&lt;/CODE&gt;.  The second part, the substitute part, is &lt;CODE&gt;) NOT (&lt;/CODE&gt;.&lt;/P&gt;

&lt;P&gt;Here's the run-anywhere examples.&lt;/P&gt;

&lt;P&gt;With spaces:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults | eval orig_field="(A=hi) OR (B=bye)" 
| rex field=orig_field mode=sed "s/ OR / NOT /g"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;With escaped parenthesis:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults | eval orig_field="(A=hi) OR (B=bye)" 
| rex field=orig_field mode=sed "s/\) OR \(/) NOT (/g"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Happy Splunking!&lt;BR /&gt;
-Rich&lt;/P&gt;</description>
      <pubDate>Wed, 29 Mar 2017 11:58:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-escape-a-parentheses-in-sed-rex-command/m-p/304329#M91515</guid>
      <dc:creator>Richfez</dc:creator>
      <dc:date>2017-03-29T11:58:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to escape a parentheses in sed rex command ?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-escape-a-parentheses-in-sed-rex-command/m-p/304330#M91516</link>
      <description>&lt;P&gt;yes this is the answer haha.. So regexes are only used in the first part of the sed, not both parts ! Thank you!&lt;/P&gt;</description>
      <pubDate>Wed, 29 Mar 2017 12:14:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-escape-a-parentheses-in-sed-rex-command/m-p/304330#M91516</guid>
      <dc:creator>DavidHourani</dc:creator>
      <dc:date>2017-03-29T12:14:15Z</dc:date>
    </item>
  </channel>
</rss>

