<?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 run rex commands from CLI mode in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-run-rex-commands-from-CLI-mode/m-p/272220#M81922</link>
    <description>&lt;P&gt;It doesn't work for me, I tried with single quote &lt;CODE&gt;'&lt;/CODE&gt; and it works. &lt;/P&gt;</description>
    <pubDate>Sat, 10 Sep 2016 16:38:21 GMT</pubDate>
    <dc:creator>vkakani60</dc:creator>
    <dc:date>2016-09-10T16:38:21Z</dc:date>
    <item>
      <title>How to run rex commands from CLI mode</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-run-rex-commands-from-CLI-mode/m-p/272218#M81920</link>
      <description>&lt;P&gt;I want to run Splunk query from the  cmd prompt. &lt;/P&gt;

&lt;P&gt;It works just fine with basic error search, but when I tried with rex extraction it doesn't recognize the pipe | and rex commands. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;splunk search "index=apps sourcetype=weblogs | rex field=_raw  "Source: (?&amp;lt;Source&amp;gt;.*)" |  dedup Source | outputtext usexml=false "  user admin password changeme
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 10 Sep 2016 04:11:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-run-rex-commands-from-CLI-mode/m-p/272218#M81920</guid>
      <dc:creator>vkakani60</dc:creator>
      <dc:date>2016-09-10T04:11:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to run rex commands from CLI mode</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-run-rex-commands-from-CLI-mode/m-p/272219#M81921</link>
      <description>&lt;P&gt;Hi vkakani60,&lt;/P&gt;

&lt;P&gt;You need to escape the &lt;CODE&gt;"&lt;/CODE&gt; of the regex &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; splunk search "index=apps sourcetype=weblogs | rex field=_raw  \"Source: (?&amp;lt;Source&amp;gt;.*)\" |  dedup Source | outputtext usexml=false "  user admin password changeme
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Hope this helps ...&lt;/P&gt;

&lt;P&gt;Cheers, MuS&lt;/P&gt;</description>
      <pubDate>Sat, 10 Sep 2016 05:08:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-run-rex-commands-from-CLI-mode/m-p/272219#M81921</guid>
      <dc:creator>MuS</dc:creator>
      <dc:date>2016-09-10T05:08:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to run rex commands from CLI mode</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-run-rex-commands-from-CLI-mode/m-p/272220#M81922</link>
      <description>&lt;P&gt;It doesn't work for me, I tried with single quote &lt;CODE&gt;'&lt;/CODE&gt; and it works. &lt;/P&gt;</description>
      <pubDate>Sat, 10 Sep 2016 16:38:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-run-rex-commands-from-CLI-mode/m-p/272220#M81922</guid>
      <dc:creator>vkakani60</dc:creator>
      <dc:date>2016-09-10T16:38:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to run rex commands from CLI mode</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-run-rex-commands-from-CLI-mode/m-p/272221#M81923</link>
      <description>&lt;P&gt;It works with single quote &lt;CODE&gt;'&lt;/CODE&gt;, for &lt;CODE&gt;\"&lt;/CODE&gt; it throws me an error &lt;CODE&gt;There is no such file.&lt;/CODE&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;splunk search "index=apps sourcetype=weblogs | rex field=_raw  'Source: (?&amp;lt;Source&amp;gt;.*)' |  dedup Source | outputtext usexml=false "  user admin password changeme
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 10 Sep 2016 16:40:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-run-rex-commands-from-CLI-mode/m-p/272221#M81923</guid>
      <dc:creator>vkakani60</dc:creator>
      <dc:date>2016-09-10T16:40:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to run rex commands from CLI mode</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-run-rex-commands-from-CLI-mode/m-p/272222#M81924</link>
      <description>&lt;P&gt;When using Splunk's CLI you have to remember that you are running under the context of the Unix Shell first and foremost.  Things you try to do will be parsed by the shell, possibly resulting in unexpected side effects, well before the Splunk CLI sees it.   Many special characters in SPL are &lt;EM&gt;also&lt;/EM&gt; special characters to the shell.  &lt;/P&gt;

&lt;P&gt;Drawing an example.  Let's take a sample Splunk search, ran from the search bar:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=access_combined host = server*
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This returns all events from my hosts named &lt;CODE&gt;server*&lt;/CODE&gt; where the sourcetype is &lt;CODE&gt;access_combined&lt;/CODE&gt;.    Now, let's run this exact same search, copied and pasted, using the CLI.  For the sake of argument, let's assume my shell is in a directory that has files named &lt;CODE&gt;server1.txt&lt;/CODE&gt; &lt;CODE&gt;server2.txt&lt;/CODE&gt; and &lt;CODE&gt;server3.txt&lt;/CODE&gt;.  So I run:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;splunk search sourcetype=access_combined host = server*
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Surprise!  I don't get the same results that I got running the search via the search bar.  Why?  Because the Shell interpreted the wildcard in &lt;CODE&gt;server*&lt;/CODE&gt; for me.  What got actually passed to Splunk was:&lt;BR /&gt;
    splunk search sourcetype=access_combined host = server1.txt server2.txt server3.txt&lt;/P&gt;

&lt;P&gt;Not at ALL what we expected!  You can see this effect with Bash and most other bash-like shells by doing a &lt;CODE&gt;set -x&lt;/CODE&gt; on the command line to enable extra output from the shell itself for debugging purposes.&lt;/P&gt;

&lt;P&gt;I'm not going to try to explain all of the different shell quoting and escaping rules, because they are rather complex and there are certainly better references - ask Google.  But, at a high level the pipe character &lt;CODE&gt;|&lt;/CODE&gt;, the back-tick character (which I cannot show here because it's also special to Answers' markup, the asterisk &lt;CODE&gt;*&lt;/CODE&gt;, single quotes, &lt;CODE&gt;'&lt;/CODE&gt;, double quotes, &lt;CODE&gt;"&lt;/CODE&gt;, and the dollar sign &lt;CODE&gt;$&lt;/CODE&gt; are all special to both the shell and Splunk in some certain way.  And this is not an exhaustive list.&lt;/P&gt;

&lt;P&gt;Trying to run an arbitrarily complex searches from the CLI will require you to know the arcane Shell quoting rules.  There is no easy way to avoid it. &lt;/P&gt;</description>
      <pubDate>Sat, 10 Sep 2016 17:58:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-run-rex-commands-from-CLI-mode/m-p/272222#M81924</guid>
      <dc:creator>dwaddle</dc:creator>
      <dc:date>2016-09-10T17:58:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to run rex commands from CLI mode</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-run-rex-commands-from-CLI-mode/m-p/272223#M81925</link>
      <description>&lt;P&gt;Another fantastic answer by duckfez!&lt;/P&gt;</description>
      <pubDate>Sat, 10 Sep 2016 20:03:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-run-rex-commands-from-CLI-mode/m-p/272223#M81925</guid>
      <dc:creator>MuS</dc:creator>
      <dc:date>2016-09-10T20:03:21Z</dc:date>
    </item>
  </channel>
</rss>

