<?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: Why curl command for CSV output of top 20 error messages using regex returns error &amp;quot; -bash: syntax error near unexpected token `(' &amp;quot;? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Why-curl-command-for-CSV-output-of-top-20-error-messages-using/m-p/128223#M34806</link>
    <description>&lt;P&gt;The reason why your command doesn't work is indeed because you're not escaping your query string and therefore it gets interpreted by the shell. The solution is simple: enclose your search string within single quotation marks.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;curl --get -s -u admin:pwd -k https:localhost:8088/servicesNS/admin/search/search/jobs/export -d output_mode=csv --data-urlencode search='search index=* sourcetype="log4j" | rex field=_raw ".*ERROR\\s+(?.*)\\n | top limit=20 ErrorMessage' -o aggregatedErrors.csv
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 20 Nov 2014 19:18:20 GMT</pubDate>
    <dc:creator>Ayn</dc:creator>
    <dc:date>2014-11-20T19:18:20Z</dc:date>
    <item>
      <title>Why curl command for CSV output of top 20 error messages using regex returns error " -bash: syntax error near unexpected token `(' "?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-curl-command-for-CSV-output-of-top-20-error-messages-using/m-p/128222#M34805</link>
      <description>&lt;P&gt;I'm trying to use the REST API to export an aggregation of the top 20 error messages in my log4j formatted logs. I want to do this through a search with Regex. Here is my curl command:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;curl --get -s -u admin:pwd -k https:localhost:8088/servicesNS/admin/search/search/jobs/export -d output_mode=csv --data-urlencode search="search index=* sourcetype="log4j" | rex field=_raw ".*ERROR\\s+(?.*)\\n | top limit=20 ErrorMessage" -o aggregatedErrors.csv
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This returns the error: -bash: syntax error near unexpected token `('&lt;/P&gt;

&lt;P&gt;The search itself works fine in the Splunk search app, but curl seems to have an issue with the search string. Any idea why? Do I need to escape characters in the regex to use with curl? The reason I'm not just picking out a pre-saved field extraction is because the field extraction shows up fine in the extractor but gives me the entire stack trace when aggregating the errors. Therefore I end up with 100+ unique values instead of 10 or 12. The regex search piped into "top limit=20..." works best. &lt;/P&gt;

&lt;P&gt;Please help!&lt;/P&gt;</description>
      <pubDate>Thu, 20 Nov 2014 18:51:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-curl-command-for-CSV-output-of-top-20-error-messages-using/m-p/128222#M34805</guid>
      <dc:creator>shantu</dc:creator>
      <dc:date>2014-11-20T18:51:17Z</dc:date>
    </item>
    <item>
      <title>Re: Why curl command for CSV output of top 20 error messages using regex returns error " -bash: syntax error near unexpected token `(' "?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-curl-command-for-CSV-output-of-top-20-error-messages-using/m-p/128223#M34806</link>
      <description>&lt;P&gt;The reason why your command doesn't work is indeed because you're not escaping your query string and therefore it gets interpreted by the shell. The solution is simple: enclose your search string within single quotation marks.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;curl --get -s -u admin:pwd -k https:localhost:8088/servicesNS/admin/search/search/jobs/export -d output_mode=csv --data-urlencode search='search index=* sourcetype="log4j" | rex field=_raw ".*ERROR\\s+(?.*)\\n | top limit=20 ErrorMessage' -o aggregatedErrors.csv
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 20 Nov 2014 19:18:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-curl-command-for-CSV-output-of-top-20-error-messages-using/m-p/128223#M34806</guid>
      <dc:creator>Ayn</dc:creator>
      <dc:date>2014-11-20T19:18:20Z</dc:date>
    </item>
    <item>
      <title>Re: Why curl command for CSV output of top 20 error messages using regex returns error " -bash: syntax error near unexpected token `(' "?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-curl-command-for-CSV-output-of-top-20-error-messages-using/m-p/128224#M34807</link>
      <description>&lt;P&gt;Awesome, that worked perfectly! Thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 20 Nov 2014 20:00:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-curl-command-for-CSV-output-of-top-20-error-messages-using/m-p/128224#M34807</guid>
      <dc:creator>shantu</dc:creator>
      <dc:date>2014-11-20T20:00:12Z</dc:date>
    </item>
  </channel>
</rss>

