<?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: rex expression does not work in curl in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/rex-expression-does-not-work-in-curl/m-p/444577#M126092</link>
    <description>&lt;P&gt;I am using windows&lt;/P&gt;</description>
    <pubDate>Thu, 02 May 2019 16:17:48 GMT</pubDate>
    <dc:creator>Sukisen1981</dc:creator>
    <dc:date>2019-05-02T16:17:48Z</dc:date>
    <item>
      <title>rex expression does not work in curl</title>
      <link>https://community.splunk.com/t5/Splunk-Search/rex-expression-does-not-work-in-curl/m-p/444562#M126077</link>
      <description>&lt;P&gt;I have a simple search on a text pad, like this &lt;CODE&gt;index=text|rex field=_raw "ApplicationRegistry-(?&amp;lt;text&amp;gt;.*)" max_match=0 |table source,sourcetype,text&lt;/CODE&gt;&lt;BR /&gt;
This works in web UI but does not work with curl&lt;CODE&gt;curl -ku admin:admin &lt;A href="https://192.168.1.4:8089/servicesNS/admin/search/jobs/export" target="test_blank"&gt;https://192.168.1.4:8089/servicesNS/admin/search/jobs/export&lt;/A&gt; --data-urlencode search=“search index%3Dtext%7Crex%20field%3D_raw%20"ApplicationRegistry-(%3F.*)"%20max_match%3D0%20%7C%20table%20host%2Csource%2Csourcetype%2Ctext” -d output_mode=json&lt;BR /&gt;
&lt;/CODE&gt;&lt;BR /&gt;
However, if i remove the rex expression and just table source,host,sourcetype the below command works&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;curl -ku admin:admin &lt;A href="https://192.168.1.4:8089/servicesNS/admin/search/search/jobs/export" target="test_blank"&gt;https://192.168.1.4:8089/servicesNS/admin/search/search/jobs/export&lt;/A&gt; -d search=“search index%3Dtext%20%7C%20table%20host%2Csource%2Csourcetype” -d output_mode=json
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Why is curl failing with rex? i receive an error - The system cannot find the file specified.&lt;BR /&gt;
I have looked at many answers here, replace -d with this or that etc. etc. but ot does not work&lt;/P&gt;</description>
      <pubDate>Wed, 01 May 2019 08:31:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/rex-expression-does-not-work-in-curl/m-p/444562#M126077</guid>
      <dc:creator>Sukisen1981</dc:creator>
      <dc:date>2019-05-01T08:31:55Z</dc:date>
    </item>
    <item>
      <title>Re: rex expression does not work in curl</title>
      <link>https://community.splunk.com/t5/Splunk-Search/rex-expression-does-not-work-in-curl/m-p/444563#M126078</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;Can you please try below command&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;curl -ku admin:admin &lt;A href="https://192.168.1.4:8089/servicesNS/admin/search/search/jobs/export" target="test_blank"&gt;https://192.168.1.4:8089/servicesNS/admin/search/search/jobs/export&lt;/A&gt; -d search="search index=text|rex field=_raw \"ApplicationRegistry-(?&amp;lt;text&amp;gt;.*)\" max_match=0 |table source,sourcetype,text" -d output_mode=json
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 01 May 2019 09:32:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/rex-expression-does-not-work-in-curl/m-p/444563#M126078</guid>
      <dc:creator>harsmarvania57</dc:creator>
      <dc:date>2019-05-01T09:32:12Z</dc:date>
    </item>
    <item>
      <title>Re: rex expression does not work in curl</title>
      <link>https://community.splunk.com/t5/Splunk-Search/rex-expression-does-not-work-in-curl/m-p/444564#M126079</link>
      <description>&lt;P&gt;Tried and received the same error message. I can see that you are trying to escape the regular expression, I guess its all on how to escape / treat the regex as a regex&lt;/P&gt;</description>
      <pubDate>Wed, 01 May 2019 10:00:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/rex-expression-does-not-work-in-curl/m-p/444564#M126079</guid>
      <dc:creator>Sukisen1981</dc:creator>
      <dc:date>2019-05-01T10:00:58Z</dc:date>
    </item>
    <item>
      <title>Re: rex expression does not work in curl</title>
      <link>https://community.splunk.com/t5/Splunk-Search/rex-expression-does-not-work-in-curl/m-p/444565#M126080</link>
      <description>&lt;P&gt;BTW does the splunk version play a role? I am on 6.6.3&lt;/P&gt;</description>
      <pubDate>Wed, 01 May 2019 10:01:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/rex-expression-does-not-work-in-curl/m-p/444565#M126080</guid>
      <dc:creator>Sukisen1981</dc:creator>
      <dc:date>2019-05-01T10:01:32Z</dc:date>
    </item>
    <item>
      <title>Re: rex expression does not work in curl</title>
      <link>https://community.splunk.com/t5/Splunk-Search/rex-expression-does-not-work-in-curl/m-p/444566#M126081</link>
      <description>&lt;P&gt;Might be, I am testing in my lab environment and above command which I posted is working fine on Splunk 7.1.2&lt;/P&gt;</description>
      <pubDate>Wed, 01 May 2019 10:16:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/rex-expression-does-not-work-in-curl/m-p/444566#M126081</guid>
      <dc:creator>harsmarvania57</dc:creator>
      <dc:date>2019-05-01T10:16:30Z</dc:date>
    </item>
    <item>
      <title>Re: rex expression does not work in curl</title>
      <link>https://community.splunk.com/t5/Splunk-Search/rex-expression-does-not-work-in-curl/m-p/444567#M126082</link>
      <description>&lt;P&gt;the thing is the customer is on 6.6.3 and I can't just tell them to upgrade to 7.x version...&lt;BR /&gt;
As far as an ideal situation goes my and your curl commands should work just fine but it is not &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 01 May 2019 10:54:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/rex-expression-does-not-work-in-curl/m-p/444567#M126082</guid>
      <dc:creator>Sukisen1981</dc:creator>
      <dc:date>2019-05-01T10:54:09Z</dc:date>
    </item>
    <item>
      <title>Re: rex expression does not work in curl</title>
      <link>https://community.splunk.com/t5/Splunk-Search/rex-expression-does-not-work-in-curl/m-p/444568#M126083</link>
      <description>&lt;P&gt;Try the example found here and see if it works - &lt;A href="https://docs.splunk.com/Documentation/Splunk/7.2.6/RESTREF/RESTsearch#search.2Fjobs.2Fexport"&gt;https://docs.splunk.com/Documentation/Splunk/7.2.6/RESTREF/RESTsearch#search.2Fjobs.2Fexport&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;I do wonder if the asterisk not being escaped/encoded in your test is the issue?&lt;/P&gt;</description>
      <pubDate>Wed, 01 May 2019 12:13:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/rex-expression-does-not-work-in-curl/m-p/444568#M126083</guid>
      <dc:creator>chris_barrett</dc:creator>
      <dc:date>2019-05-01T12:13:37Z</dc:date>
    </item>
    <item>
      <title>Re: rex expression does not work in curl</title>
      <link>https://community.splunk.com/t5/Splunk-Search/rex-expression-does-not-work-in-curl/m-p/444569#M126084</link>
      <description>&lt;P&gt;Hi &lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/139711"&gt;@chris_barrett&lt;/a&gt; and &lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/163905"&gt;@harsmarvania57&lt;/a&gt; . To make things more generic I have now used the audit command so that we can all replicate the issue. So, this works - &lt;BR /&gt;
     curl -ku admin:admin &lt;A href="https://192.168.1.5:8089/servicesNS/admin/search/search/jobs/export" target="_blank"&gt;https://192.168.1.5:8089/servicesNS/admin/search/search/jobs/export&lt;/A&gt; -d search=“search index="_audit"|table source,host,text” -d output_mode=json&lt;/P&gt;

&lt;P&gt;In the splunk web UI this works - &lt;BR /&gt;
    index="_audit"|rex field=_raw "Audit:(?&lt;TEXT&gt;.*)" |table source,host,text&lt;BR /&gt;
But if i use curl to fetch the rex, it fails. So this does not work&lt;/TEXT&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; curl -ku admin:admin https://192.168.1.5:8089/servicesNS/admin/search/search/jobs/export -d search=“index="_audit"|rex field=_raw "Audit:(?&amp;lt;text&amp;gt;.*)" |table source,host,text" |table source,host,text” -d output_mode=json
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I know its about escaping/writing the regex inside the curl command, but what is the way to do that?&lt;BR /&gt;
I did refer to this answer here - &lt;A href="https://answers.splunk.com/answers/495305/why-is-rex-field-not-producing-results-when-used-i.html" target="_blank"&gt;https://answers.splunk.com/answers/495305/why-is-rex-field-not-producing-results-when-used-i.html&lt;/A&gt;&lt;BR /&gt;
But this does not work, curious to know if you guys try the _audit index with the rex as stated above are you receiving results from the curl command?&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 00:24:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/rex-expression-does-not-work-in-curl/m-p/444569#M126084</guid>
      <dc:creator>Sukisen1981</dc:creator>
      <dc:date>2020-09-30T00:24:05Z</dc:date>
    </item>
    <item>
      <title>Re: rex expression does not work in curl</title>
      <link>https://community.splunk.com/t5/Splunk-Search/rex-expression-does-not-work-in-curl/m-p/444570#M126085</link>
      <description>&lt;P&gt;Replace your opening and closing quotation marks with single ticks to define the contents as a literal string.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; curl -ku admin:admin &lt;A href="https://192.168.1.4:8089/servicesNS/admin/search/search/jobs/export" target="test_blank"&gt;https://192.168.1.4:8089/servicesNS/admin/search/search/jobs/export&lt;/A&gt; -d search='search index=text|rex field=_raw \"ApplicationRegistry-(?&amp;lt;text&amp;gt;.*)\" max_match=0 |table source,sourcetype,text' -d output_mode=json
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Then it should work for you.&lt;/P&gt;</description>
      <pubDate>Wed, 01 May 2019 19:35:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/rex-expression-does-not-work-in-curl/m-p/444570#M126085</guid>
      <dc:creator>codebuilder</dc:creator>
      <dc:date>2019-05-01T19:35:41Z</dc:date>
    </item>
    <item>
      <title>Re: rex expression does not work in curl</title>
      <link>https://community.splunk.com/t5/Splunk-Search/rex-expression-does-not-work-in-curl/m-p/444571#M126086</link>
      <description>&lt;P&gt;does not work. I receive the same message in CMD &lt;/P&gt;</description>
      <pubDate>Thu, 02 May 2019 06:54:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/rex-expression-does-not-work-in-curl/m-p/444571#M126086</guid>
      <dc:creator>Sukisen1981</dc:creator>
      <dc:date>2019-05-02T06:54:18Z</dc:date>
    </item>
    <item>
      <title>Re: rex expression does not work in curl</title>
      <link>https://community.splunk.com/t5/Splunk-Search/rex-expression-does-not-work-in-curl/m-p/444572#M126087</link>
      <description>&lt;P&gt;Hi @Sukisen1981,&lt;/P&gt;

&lt;P&gt;This is working for me : &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;curl -ku admin:admin &lt;A href="https://127.0.0.1:8089/servicesNS/admin/search/search/jobs/export" target="test_blank"&gt;https://127.0.0.1:8089/servicesNS/admin/search/search/jobs/export&lt;/A&gt; -d search='search index="_audit" user=* |head 1 | rex field=_raw "user=(?&amp;lt;text&amp;gt;[^\s,]*)" | table source text'  -d output_mode=json 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;and this as well :&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;curl -ku admin:admin &lt;A href="https://127.0.0.1:8089/servicesNS/admin/search/search/jobs/export" target="test_blank"&gt;https://127.0.0.1:8089/servicesNS/admin/search/search/jobs/export&lt;/A&gt; -d search='search index="_audit" user=* |head 1 |rex field=_raw "Audit:(?&amp;lt;text&amp;gt;.*)" | table source text'  -d output_mode=json
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Could you please try and let me know if it works for you. Also which version of Splunk are you currently &lt;BR /&gt;
using ? It could be a problem specific to your current version.&lt;/P&gt;

&lt;P&gt;Cheers,&lt;BR /&gt;
David&lt;/P&gt;</description>
      <pubDate>Thu, 02 May 2019 07:56:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/rex-expression-does-not-work-in-curl/m-p/444572#M126087</guid>
      <dc:creator>DavidHourani</dc:creator>
      <dc:date>2019-05-02T07:56:45Z</dc:date>
    </item>
    <item>
      <title>Re: rex expression does not work in curl</title>
      <link>https://community.splunk.com/t5/Splunk-Search/rex-expression-does-not-work-in-curl/m-p/444573#M126088</link>
      <description>&lt;P&gt;Maybe noob question and not relevant but still asking, are you using curl on Linux or on Windows ?&lt;/P&gt;</description>
      <pubDate>Thu, 02 May 2019 08:14:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/rex-expression-does-not-work-in-curl/m-p/444573#M126088</guid>
      <dc:creator>harsmarvania57</dc:creator>
      <dc:date>2019-05-02T08:14:19Z</dc:date>
    </item>
    <item>
      <title>Re: rex expression does not work in curl</title>
      <link>https://community.splunk.com/t5/Splunk-Search/rex-expression-does-not-work-in-curl/m-p/444574#M126089</link>
      <description>&lt;P&gt;Receive error 'head' is not recognized as an internal or external command, in both cases,once again I am on splunk 6.63, is that having any effect?&lt;BR /&gt;
It is getting a bit irritating now, for the moment we are managing without the rex fields but we really wanted to have the regex fields to be extracted through splunk before using the API JSON output in the downstream UI system...&lt;/P&gt;</description>
      <pubDate>Thu, 02 May 2019 11:01:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/rex-expression-does-not-work-in-curl/m-p/444574#M126089</guid>
      <dc:creator>Sukisen1981</dc:creator>
      <dc:date>2019-05-02T11:01:09Z</dc:date>
    </item>
    <item>
      <title>Re: rex expression does not work in curl</title>
      <link>https://community.splunk.com/t5/Splunk-Search/rex-expression-does-not-work-in-curl/m-p/444575#M126090</link>
      <description>&lt;P&gt;I'm testing on the same version now, working on linux.. What distro are you using ? you can get rid of the head 1 if you like it's just for reducing the number of events. Could you try it on your splunk GUI first, run the command with the exact user you are using for the curl command see what it does and if it gives results. If it's working on GUI and you're using admin for CLI it should work &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; &lt;BR /&gt;
Also could be a problem with the path for your curl command if you're using windows..&lt;/P&gt;</description>
      <pubDate>Thu, 02 May 2019 11:17:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/rex-expression-does-not-work-in-curl/m-p/444575#M126090</guid>
      <dc:creator>DavidHourani</dc:creator>
      <dc:date>2019-05-02T11:17:37Z</dc:date>
    </item>
    <item>
      <title>Re: rex expression does not work in curl</title>
      <link>https://community.splunk.com/t5/Splunk-Search/rex-expression-does-not-work-in-curl/m-p/444576#M126091</link>
      <description>&lt;P&gt;Hi @DavidHourani  - I am on windows so I need to replace the single quote after the first appearance of the word 'search' with double quotes,but that does not still solve the original error message.&lt;BR /&gt;
It is a problem with the path in windows for sure - the message is The system cannot find the file specified. But what is the solution :)?&lt;BR /&gt;
The rex works in the UI , does not really matter if the rex returns results or not, it should not error out in the UI and that's not happening in the UI&lt;/P&gt;</description>
      <pubDate>Thu, 02 May 2019 16:17:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/rex-expression-does-not-work-in-curl/m-p/444576#M126091</guid>
      <dc:creator>Sukisen1981</dc:creator>
      <dc:date>2019-05-02T16:17:23Z</dc:date>
    </item>
    <item>
      <title>Re: rex expression does not work in curl</title>
      <link>https://community.splunk.com/t5/Splunk-Search/rex-expression-does-not-work-in-curl/m-p/444577#M126092</link>
      <description>&lt;P&gt;I am using windows&lt;/P&gt;</description>
      <pubDate>Thu, 02 May 2019 16:17:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/rex-expression-does-not-work-in-curl/m-p/444577#M126092</guid>
      <dc:creator>Sukisen1981</dc:creator>
      <dc:date>2019-05-02T16:17:48Z</dc:date>
    </item>
    <item>
      <title>Re: rex expression does not work in curl</title>
      <link>https://community.splunk.com/t5/Splunk-Search/rex-expression-does-not-work-in-curl/m-p/444578#M126093</link>
      <description>&lt;P&gt;what you're facing is a windows related problem with Curl, not a Splunk problem, what you could do is write a small script that ads the query in a variable and send the variable instead of typing the search &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; &lt;/P&gt;</description>
      <pubDate>Thu, 02 May 2019 16:41:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/rex-expression-does-not-work-in-curl/m-p/444578#M126093</guid>
      <dc:creator>DavidHourani</dc:creator>
      <dc:date>2019-05-02T16:41:36Z</dc:date>
    </item>
    <item>
      <title>Re: rex expression does not work in curl</title>
      <link>https://community.splunk.com/t5/Splunk-Search/rex-expression-does-not-work-in-curl/m-p/444579#M126094</link>
      <description>&lt;P&gt;Hi @DavidHourani  - Is there any pointer to the script you are referring to? I realize that this is a windows specific issue , but alas I can not ask the client to use Linux just for this issue.&lt;BR /&gt;
I have posted the same question on stack today, awaiting answers from from bash experts over there and also trying to install cygwin.&lt;BR /&gt;
On this not being a splunk issue, I disagree - No where in the curl docs that splunk mention something like this can occur whilst using windows, and well, a major product vendor can not provide features that give issues on one of the most widely used OS in the world.&lt;BR /&gt;
But that is besides the point, thanks for your reply I am now investigating other alternatives to make this work on windows. Once again, many thanks&lt;/P&gt;</description>
      <pubDate>Fri, 03 May 2019 17:46:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/rex-expression-does-not-work-in-curl/m-p/444579#M126094</guid>
      <dc:creator>Sukisen1981</dc:creator>
      <dc:date>2019-05-03T17:46:25Z</dc:date>
    </item>
    <item>
      <title>Re: rex expression does not work in curl</title>
      <link>https://community.splunk.com/t5/Splunk-Search/rex-expression-does-not-work-in-curl/m-p/444580#M126095</link>
      <description>&lt;P&gt;Hi @Sukisen1981,&lt;BR /&gt;
You're welcome, yeah I agree on your point of view about Windows/Splunk issues. Problem is that not all commands used for Linux and then re-adapted for Windows are integrated in the same way so escaping characters doesn't always work as you'd expect it. Cygwin might solve the problem for you as well (Let me know if it does &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; ). &lt;/P&gt;

&lt;P&gt;As for the scripts, have a look here : &lt;BR /&gt;
&lt;A href="https://linuxhint.com/curl_bash_examples/"&gt;https://linuxhint.com/curl_bash_examples/&lt;/A&gt; &lt;BR /&gt;
The idea is to put the whole Splunk query in a variable and reuse the variable name in the curl command.&lt;/P&gt;</description>
      <pubDate>Sat, 04 May 2019 08:32:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/rex-expression-does-not-work-in-curl/m-p/444580#M126095</guid>
      <dc:creator>DavidHourani</dc:creator>
      <dc:date>2019-05-04T08:32:24Z</dc:date>
    </item>
    <item>
      <title>Re: rex expression does not work in curl</title>
      <link>https://community.splunk.com/t5/Splunk-Search/rex-expression-does-not-work-in-curl/m-p/444581#M126096</link>
      <description>&lt;P&gt;Hi @DavidHourani -&lt;BR /&gt;
Cygwin works and ultimately of course I wanted to eventually use the REST api edn points on 8089 , wrote a small python script of 5-6 lines and it works.&lt;BR /&gt;
Many thanks for your help , I am gonna up vote a couple of your comments since you really digged into this&lt;/P&gt;</description>
      <pubDate>Sat, 11 May 2019 08:23:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/rex-expression-does-not-work-in-curl/m-p/444581#M126096</guid>
      <dc:creator>Sukisen1981</dc:creator>
      <dc:date>2019-05-11T08:23:43Z</dc:date>
    </item>
  </channel>
</rss>

