<?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 trim the last line from query in Dashboards &amp; Visualizations</title>
    <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-trim-the-last-line-from-query/m-p/409740#M26909</link>
    <description>&lt;P&gt;Adding to @richgalloway 's answer, the full regex would look like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval job.search="index=\"idx2\" report=\"ABC\" | table number,description,description,group,sev ,closurec, created, state, closed_date | timechart count by state"
| rex  field=job.search "(?&amp;lt;search&amp;gt;.*)\s*\|[^\|]+"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;CODE&gt;(?&amp;lt;search&amp;gt;.*)\s*\|[^\|]+&lt;/CODE&gt;&lt;BR /&gt;
&lt;CODE&gt;(?&amp;lt;search&amp;gt;.*)&lt;/CODE&gt; - Grab everything &lt;CODE&gt;.*&lt;/CODE&gt; in the job.search field and assign it to the new field &lt;CODE&gt;search&lt;/CODE&gt;&lt;BR /&gt;
&lt;CODE&gt;\s*\|[^\|]+&lt;/CODE&gt; - Match anything with any number of spaces &lt;CODE&gt;\s&lt;/CODE&gt; followed by a pipe &lt;CODE&gt;|&lt;/CODE&gt; followed by any number of non-pipe characters &lt;CODE&gt;[^\|]+&lt;/CODE&gt;. Since they are not within the parentheses, all matching characters are discarded.&lt;/P&gt;

&lt;P&gt;You could also force it to match the timechart command:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval job.search="index=\"idx2\" report=\"ABC\" | table number,description,description,group,sev ,closurec, created, state, closed_date | timechart count by state"
| rex  field=job.search "(?&amp;lt;search&amp;gt;.*)\s*\|\s*timechart[^\|]+"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 29 Jul 2019 18:46:28 GMT</pubDate>
    <dc:creator>jacobpevans</dc:creator>
    <dc:date>2019-07-29T18:46:28Z</dc:date>
    <item>
      <title>How to trim the last line from query</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-trim-the-last-line-from-query/m-p/409738#M26907</link>
      <description>&lt;P&gt;Hi , &lt;BR /&gt;
I am passing my search query in token using $job.search$, want to remove the last line from the query.&lt;BR /&gt;
For example , my query is &lt;BR /&gt;
&lt;CODE&gt;index="idx2" report="ABC" &lt;BR /&gt;
| table number,description,description,group,sev ,closurec, created, state, closed_date&lt;BR /&gt;
| timechart count by state&lt;/CODE&gt;&lt;BR /&gt;
So , I want to evaluate/pass only below in defined token&lt;BR /&gt;
&lt;CODE&gt;index="idx2" report="ABC" &lt;BR /&gt;
| table number,description,description,group,sev ,closurec, created, state, closed_date&lt;/CODE&gt;&lt;BR /&gt;
Please let me know , how to remove the line after last occurrence of  pipe"|" and retain all things before it.&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jul 2019 17:54:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-trim-the-last-line-from-query/m-p/409738#M26907</guid>
      <dc:creator>avni26</dc:creator>
      <dc:date>2019-07-29T17:54:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to trim the last line from query</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-trim-the-last-line-from-query/m-p/409739#M26908</link>
      <description>&lt;P&gt;It's not clear at what point you want to change $job.search$, but you may be able to use &lt;CODE&gt;rex&lt;/CODE&gt;.   &lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;... | eval search=$job.search$ | rex field=search "(?&amp;lt;token&amp;gt;.*)\|" | ...&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jul 2019 18:17:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-trim-the-last-line-from-query/m-p/409739#M26908</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2019-07-29T18:17:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to trim the last line from query</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-trim-the-last-line-from-query/m-p/409740#M26909</link>
      <description>&lt;P&gt;Adding to @richgalloway 's answer, the full regex would look like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval job.search="index=\"idx2\" report=\"ABC\" | table number,description,description,group,sev ,closurec, created, state, closed_date | timechart count by state"
| rex  field=job.search "(?&amp;lt;search&amp;gt;.*)\s*\|[^\|]+"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;CODE&gt;(?&amp;lt;search&amp;gt;.*)\s*\|[^\|]+&lt;/CODE&gt;&lt;BR /&gt;
&lt;CODE&gt;(?&amp;lt;search&amp;gt;.*)&lt;/CODE&gt; - Grab everything &lt;CODE&gt;.*&lt;/CODE&gt; in the job.search field and assign it to the new field &lt;CODE&gt;search&lt;/CODE&gt;&lt;BR /&gt;
&lt;CODE&gt;\s*\|[^\|]+&lt;/CODE&gt; - Match anything with any number of spaces &lt;CODE&gt;\s&lt;/CODE&gt; followed by a pipe &lt;CODE&gt;|&lt;/CODE&gt; followed by any number of non-pipe characters &lt;CODE&gt;[^\|]+&lt;/CODE&gt;. Since they are not within the parentheses, all matching characters are discarded.&lt;/P&gt;

&lt;P&gt;You could also force it to match the timechart command:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval job.search="index=\"idx2\" report=\"ABC\" | table number,description,description,group,sev ,closurec, created, state, closed_date | timechart count by state"
| rex  field=job.search "(?&amp;lt;search&amp;gt;.*)\s*\|\s*timechart[^\|]+"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 29 Jul 2019 18:46:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-trim-the-last-line-from-query/m-p/409740#M26909</guid>
      <dc:creator>jacobpevans</dc:creator>
      <dc:date>2019-07-29T18:46:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to trim the last line from query</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-trim-the-last-line-from-query/m-p/409741#M26910</link>
      <description>&lt;P&gt;@richgalloway wanted this for drilldown to open in new window. For this I am passing whole search query in one token  to drilldown. But facing challenge when query  conatins stats/timechart at the end.&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jul 2019 18:59:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-trim-the-last-line-from-query/m-p/409741#M26910</guid>
      <dc:creator>avni26</dc:creator>
      <dc:date>2019-07-29T18:59:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to trim the last line from query</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-trim-the-last-line-from-query/m-p/409742#M26911</link>
      <description>&lt;P&gt;I am trying something like this inside the search query, but Its not working&lt;/P&gt;

&lt;P&gt;replace($job.search$,"\[|\]|\"","")&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jul 2019 19:07:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-trim-the-last-line-from-query/m-p/409742#M26911</guid>
      <dc:creator>avni26</dc:creator>
      <dc:date>2019-07-29T19:07:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to trim the last line from query</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-trim-the-last-line-from-query/m-p/409743#M26912</link>
      <description>&lt;P&gt;Try editing the token as part of the drilldown.  Edit the source dashboard's source and you'll see something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;drilldown&amp;gt;
  &amp;lt;link target="_blank"&amp;gt;search?q=$job.search$&amp;amp;amp;earliest=$field1.earliest$&amp;amp;amp;latest=$field1.latest$&amp;lt;/link&amp;gt;
&amp;lt;/drilldown&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;A little-known feature of Simple XML is the ability to modify tokens before invoking the drilldown.  I haven't done a lot with this feature, so I'm not sure of all it can do or even if it can do what is below.  Experiment and let us know how it goes.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;drilldown&amp;gt;
  &amp;lt;eval token="job_search"&amp;gt;$job.search$&amp;lt;/eval&amp;gt;
  &amp;lt;eval token="srch"&amp;gt;rex field=$job_search$ "(?&amp;lt;srch&amp;gt;.*)\|"&amp;lt;/eval&amp;gt;
  &amp;lt;link target="_blank"&amp;gt;search?q=index=$srch$&amp;amp;amp;earliest=$field1.earliest$&amp;amp;amp;latest=$field1.latest$&amp;lt;/link&amp;gt;
&amp;lt;/drilldown&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 29 Jul 2019 19:40:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-trim-the-last-line-from-query/m-p/409743#M26912</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2019-07-29T19:40:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to trim the last line from query</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-trim-the-last-line-from-query/m-p/409744#M26913</link>
      <description>&lt;P&gt;@richgalloway &lt;BR /&gt;
Thank you for your response. It not worked. After using rex field, drilldown coming like below&lt;BR /&gt;
rex field=search index="idx2" report="ABC" | table number,description,description,group,sev ,closurec, created, state, closed_date | timechart count by state "(?.*)|"&lt;BR /&gt;
Please suggest.&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jul 2019 11:10:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-trim-the-last-line-from-query/m-p/409744#M26913</guid>
      <dc:creator>avni26</dc:creator>
      <dc:date>2019-07-30T11:10:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to trim the last line from query</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-trim-the-last-line-from-query/m-p/409745#M26914</link>
      <description>&lt;P&gt;What does your &lt;CODE&gt;&amp;lt;drilldown&amp;gt;&lt;/CODE&gt; paragraph look like?&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jul 2019 14:04:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-trim-the-last-line-from-query/m-p/409745#M26914</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2019-07-30T14:04:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to trim the last line from query</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-trim-the-last-line-from-query/m-p/409746#M26915</link>
      <description>&lt;P&gt;@richgalloway Please see below.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;search&amp;gt;
 &amp;lt;query&amp;gt;index="idx2" report="ABC" | table 
  number,description,description,group,sev,closurec, created, state, closed_date
  |stats count by state                 
  &amp;lt;/query&amp;gt;
  &amp;lt;set token="job_search"&amp;gt;$job.search$&amp;lt;/set&amp;gt;
  &amp;lt;set token="srch"&amp;gt;rex field=$job_search$ "(?.*)\|"&amp;lt;/set&amp;gt;
 &amp;lt;/search&amp;gt;
 &amp;lt;option name="drilldown"&amp;gt;cell&amp;lt;/option&amp;gt;
 &amp;lt;drilldown&amp;gt;
  &amp;lt;link target="_blank"&amp;gt;search?q=$srch$&amp;amp;amp;earliest=$field1.earliest$&amp;amp;amp;latest=$field1.latest$&amp;amp;amp;form.sel_group=$sel_group$&amp;amp;amp;;display.page.search.mode=smart&amp;amp;amp;dispatch.sample_ratio=1%0A&amp;amp;amp;workload_pool=&amp;amp;amp;display.page.search.tab=statistics&amp;amp;amp;display.general.type=statistics
 &amp;lt;/drilldown&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 30 Jul 2019 16:07:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-trim-the-last-line-from-query/m-p/409746#M26915</guid>
      <dc:creator>avni26</dc:creator>
      <dc:date>2019-07-30T16:07:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to trim the last line from query</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-trim-the-last-line-from-query/m-p/409747#M26916</link>
      <description>&lt;P&gt;Have you &lt;EM&gt;tried&lt;/EM&gt; the code from my answer?  The code that uses &lt;CODE&gt;&amp;lt;eval token...&lt;/CODE&gt; and not &lt;CODE&gt;&amp;lt;set token...&lt;/CODE&gt;?  The &lt;CODE&gt;eval&lt;/CODE&gt; and &lt;CODE&gt;set&lt;/CODE&gt; options do different things.&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jul 2019 16:48:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-trim-the-last-line-from-query/m-p/409747#M26916</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2019-07-30T16:48:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to trim the last line from query</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-trim-the-last-line-from-query/m-p/409748#M26917</link>
      <description>&lt;P&gt;Yes , that also not worked. &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jul 2019 07:12:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-trim-the-last-line-from-query/m-p/409748#M26917</guid>
      <dc:creator>avni26</dc:creator>
      <dc:date>2019-07-31T07:12:43Z</dc:date>
    </item>
  </channel>
</rss>

