<?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: Can a search string dynamically build commands, and then run them? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Can-a-search-string-dynamically-build-commands-and-then-run-them/m-p/225694#M66570</link>
    <description>&lt;P&gt;The solution I came up with (mentioned in my previous comment) was flawed, because &lt;CODE&gt;xyseries&lt;/CODE&gt; does not produce the same "intelligent" X-axis labels as &lt;CODE&gt;timechart&lt;/CODE&gt;. @Jeremiah provided the following improved solution (in response to a &lt;A href="https://answers.splunk.com/answers/398911/how-do-you-make-output-from-xyseries-generate-the.html"&gt;different question&lt;/A&gt;&lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=my_log_type | bin _time | stats count by _time, conn_type | lookup connection_types.csv conn_type output description | timechart sum(count) as count by description
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 03 May 2016 06:39:54 GMT</pubDate>
    <dc:creator>Graham_Hanningt</dc:creator>
    <dc:date>2016-05-03T06:39:54Z</dc:date>
    <item>
      <title>Can a search string dynamically build commands, and then run them?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-a-search-string-dynamically-build-commands-and-then-run-them/m-p/225680#M66556</link>
      <description>&lt;P&gt;My use case: I want to create a timechart of the number (count) of requests to a system, split by "connection type": that is, how the requests arrived at the system.&lt;/P&gt;

&lt;P&gt;The request type is represented in the log as a field named &lt;CODE&gt;conn_type&lt;/CODE&gt; containing a fixed-length string of 8 characters, where each character represents a hexadecimal digit. For example, the value &lt;CODE&gt;"0000000A"&lt;/CODE&gt; indicates that the request is from system XYZ.&lt;/P&gt;

&lt;P&gt;I want the timechart legend to show descriptive labels, not these hex values. For example, instead of "0000000A", I want the legend to show something like "From system XYZ".&lt;/P&gt;

&lt;P&gt;I could replace all of the original values with readable values before creating the timechart. For example:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | eval conn_type=case(conn_type=="0000000A", "From system XYZ", ...) | timechart ...
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;but I'd prefer to use a technique that doesn't involve processing every input event for the timechart. That seems like too much processing.&lt;/P&gt;

&lt;P&gt;I'd prefer to rename the fields after the &lt;CODE&gt;timechart&lt;/CODE&gt; command, like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | timechart count by conn_type | rename "0000000A" as "From system XYZ", "0000000B" as "Entered on the command line" ...
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;That works, but I wonder, rather than coding this &lt;CODE&gt;rename&lt;/CODE&gt; command inline, I could use a CSV file as a lookup, and dynamically build the &lt;CODE&gt;rename&lt;/CODE&gt; command. Hence this question.&lt;/P&gt;

&lt;P&gt;For example, given the CSV file &lt;CODE&gt;connection_types.csv&lt;/CODE&gt; with the following structure:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;conn_type,description
0000000A,From system XYZ
0000000B,Entered on the command line
...
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;(There are a dozen or so connection types.)&lt;/P&gt;

&lt;P&gt;can I use a subsearch to build a &lt;CODE&gt;rename&lt;/CODE&gt; command as a string, as done by this search string:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|inputlookup connection_types.csv | table conn_type description | eval rename_phrase=conn_type + " as " + "\"" + description + "\"" | stats values(rename_phrase) as rename_phrases | eval search="rename " + mvjoin(rename_phrases,", ") | fields search
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;and then - here's the trick - run that returned string as a command?&lt;/P&gt;

&lt;P&gt;For now, I'll use &lt;CODE&gt;rename&lt;/CODE&gt; after the &lt;CODE&gt;timechart&lt;/CODE&gt; - it works - but I'm curious to know whether what I've described here is possible.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Apr 2016 05:14:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-a-search-string-dynamically-build-commands-and-then-run-them/m-p/225680#M66556</guid>
      <dc:creator>Graham_Hanningt</dc:creator>
      <dc:date>2016-04-28T05:14:31Z</dc:date>
    </item>
    <item>
      <title>Re: Can a search string dynamically build commands, and then run them?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-a-search-string-dynamically-build-commands-and-then-run-them/m-p/225681#M66557</link>
      <description>&lt;P&gt;Hi Graham,&lt;/P&gt;

&lt;P&gt;If I understand your question correctly, you should do the lookup for conn_type before timechart, and count by the output field (i.e., description), e.g.,&lt;/P&gt;

&lt;P&gt;test.log:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Thu Apr 28 18:59:56 CST 2016 conn_type=0000000A
Thu Apr 28 19:00:06 CST 2016 conn_type=0000000B
Thu Apr 28 19:02:48 CST 2016 conn_type=0000000B
Thu Apr 28 19:02:51 CST 2016 conn_type=0000000C
Thu Apr 28 19:02:53 CST 2016 conn_type=0000000A
Thu Apr 28 19:02:56 CST 2016 conn_type=0000000D
Thu Apr 28 19:02:59 CST 2016 conn_type=0000000B
Thu Apr 28 19:02:59 CST 2016 conn_type=0000000A
Thu Apr 28 19:03:00 CST 2016 conn_type=0000000A
Thu Apr 28 19:03:00 CST 2016 conn_type=0000000A
Thu Apr 28 19:03:01 CST 2016 conn_type=0000000B
Thu Apr 28 19:03:02 CST 2016 conn_type=0000000D
Thu Apr 28 19:03:03 CST 2016 conn_type=0000000B
Thu Apr 28 19:03:04 CST 2016 conn_type=0000000B
Thu Apr 28 19:03:05 CST 2016 conn_type=0000000D
Thu Apr 28 19:03:07 CST 2016 conn_type=0000000A
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;search command:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;source=*test.log | lookup connection_types.csv conn_type OUTPUT description | timechart count by description
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;then you'll get something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;_time   Entered on the command line From system XYZ NULL
2016-04-29 09:02:40 0   0   0
2016-04-29 09:02:45 1   0   0
2016-04-29 09:02:50 0   1   1
2016-04-29 09:02:55 1   1   1
2016-04-29 09:03:00 3   2   1
2016-04-29 09:03:05 0   1   1
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;HTH,&lt;BR /&gt;
Bill&lt;/P&gt;</description>
      <pubDate>Thu, 28 Apr 2016 11:13:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-a-search-string-dynamically-build-commands-and-then-run-them/m-p/225681#M66557</guid>
      <dc:creator>bchung_splunk</dc:creator>
      <dc:date>2016-04-28T11:13:28Z</dc:date>
    </item>
    <item>
      <title>Re: Can a search string dynamically build commands, and then run them?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-a-search-string-dynamically-build-commands-and-then-run-them/m-p/225682#M66558</link>
      <description>&lt;P&gt;If you do the lookup before &lt;CODE&gt;timechart&lt;/CODE&gt; there's no need for rename.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | lookup connection_types.csv conn_type OUTPUT description | timechart count by description 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 28 Apr 2016 11:45:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-a-search-string-dynamically-build-commands-and-then-run-them/m-p/225682#M66558</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2016-04-28T11:45:59Z</dc:date>
    </item>
    <item>
      <title>Re: Can a search string dynamically build commands, and then run them?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-a-search-string-dynamically-build-commands-and-then-run-them/m-p/225683#M66559</link>
      <description>&lt;P&gt;I believe that you can use the approach listed here with some adjustments; the key is the &lt;CODE&gt;map&lt;/CODE&gt; command:&lt;/P&gt;

&lt;P&gt;&lt;A href="https://answers.splunk.com/answers/386488/regex-in-lookuptable.html#answer-387536"&gt;https://answers.splunk.com/answers/386488/regex-in-lookuptable.html#answer-387536&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Apr 2016 17:11:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-a-search-string-dynamically-build-commands-and-then-run-them/m-p/225683#M66559</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2016-04-28T17:11:58Z</dc:date>
    </item>
    <item>
      <title>Re: Can a search string dynamically build commands, and then run them?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-a-search-string-dynamically-build-commands-and-then-run-them/m-p/225684#M66560</link>
      <description>&lt;P&gt;Thanks! And, yes, you're absolutely correct.&lt;/P&gt;

&lt;P&gt;However, the following point from my question remains:&lt;/P&gt;

&lt;BLOCKQUOTE&gt;
&lt;P&gt;I could replace all of the original values with readable values before creating the timechart [...] but &lt;EM&gt;I'd prefer to use a technique that doesn't involve processing every input event for the timechart&lt;/EM&gt;. That seems like too much processing.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;

&lt;P&gt;The &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.4.0/SearchReference/Lookup"&gt;Splunk documentation&lt;/A&gt; makes the same point:&lt;/P&gt;

&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;STRONG&gt;Optimizing your lookup search&lt;/STRONG&gt;&lt;BR /&gt;
If you are using the lookup command in the same pipeline as a transforming command, and it is possible to retain the field you will lookup on after the transforming command, do the lookup after the transforming command.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;

&lt;P&gt;This morning, I came up with the following solution:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=my_log_type | timechart count by conn_type | untable _time conn_type value | lookup connection_types.csv conn_type output description | xyseries _time description value
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This uses &lt;CODE&gt;untable&lt;/CODE&gt; and &lt;CODE&gt;xyseries&lt;/CODE&gt; with &lt;CODE&gt;lookup&lt;/CODE&gt; instead of renaming fields.&lt;/P&gt;

&lt;P&gt;I now have a solution for my use case, so my original question about dynamically building commands is, to me, academic (until I hit a use case that needs it).&lt;/P&gt;

&lt;P&gt;Thanks again for your input. Your answer prompted me to think harder about how to do the lookup &lt;EM&gt;after&lt;/EM&gt; &lt;CODE&gt;timechart&lt;/CODE&gt;.&lt;/P&gt;</description>
      <pubDate>Fri, 29 Apr 2016 03:30:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-a-search-string-dynamically-build-commands-and-then-run-them/m-p/225684#M66560</guid>
      <dc:creator>Graham_Hanningt</dc:creator>
      <dc:date>2016-04-29T03:30:48Z</dc:date>
    </item>
    <item>
      <title>Re: Can a search string dynamically build commands, and then run them?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-a-search-string-dynamically-build-commands-and-then-run-them/m-p/225685#M66561</link>
      <description>&lt;P&gt;Hi Bill,&lt;/P&gt;

&lt;P&gt;Thanks very much for the detailed answer.&lt;/P&gt;

&lt;P&gt;However:&lt;/P&gt;

&lt;BLOCKQUOTE&gt;
&lt;P&gt;you should do the lookup for conn_type before timechart&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;

&lt;P&gt;I disagree. For details, see my comment on the answer by @richgalloway.&lt;/P&gt;</description>
      <pubDate>Fri, 29 Apr 2016 03:41:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-a-search-string-dynamically-build-commands-and-then-run-them/m-p/225685#M66561</guid>
      <dc:creator>Graham_Hanningt</dc:creator>
      <dc:date>2016-04-29T03:41:59Z</dc:date>
    </item>
    <item>
      <title>Re: Can a search string dynamically build commands, and then run them?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-a-search-string-dynamically-build-commands-and-then-run-them/m-p/225686#M66562</link>
      <description>&lt;P&gt;Thanks for the tip about the &lt;CODE&gt;map&lt;/CODE&gt; command, and for the link. &lt;/P&gt;

&lt;P&gt;I've read and reread your answer to that question carefully, and recaffeinated ;-), but I cannot see how to adjust that approach for my use case. In the meantime, I've developed a solution for my use case that avoids this question. For details, see my comment on the answer by @richgalloway. (I'll admit, this demotivates me from spending more time right now looking into &lt;CODE&gt;map&lt;/CODE&gt;.)&lt;/P&gt;

&lt;P&gt;Still, I suspect that &lt;CODE&gt;map&lt;/CODE&gt; is as close an answer as I'm going to get (to this specific question about dynamically building commands)  without delving into developing a custom search command in Python.&lt;/P&gt;

&lt;P&gt;If this is still the best answer after the weekend, I'll accept it. Thanks again!&lt;/P&gt;</description>
      <pubDate>Fri, 29 Apr 2016 05:15:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-a-search-string-dynamically-build-commands-and-then-run-them/m-p/225686#M66562</guid>
      <dc:creator>Graham_Hanningt</dc:creator>
      <dc:date>2016-04-29T05:15:36Z</dc:date>
    </item>
    <item>
      <title>Re: Can a search string dynamically build commands, and then run them?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-a-search-string-dynamically-build-commands-and-then-run-them/m-p/225687#M66563</link>
      <description>&lt;P&gt;Hi Graham, &lt;/P&gt;

&lt;P&gt;If lookup before timechart isn't what you're looking for (I guess you have many events but only few conn types), &lt;BR /&gt;
have you consider using custom search command?&lt;/P&gt;

&lt;P&gt;here's a simple script that might work for you (might still need to be tuned to really work for you):&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;#!/usr/bin/env python
# -*- coding: utf-8 -*-

import splunk.Intersplunk as sis
(a, kwargs) = sis.getKeywordsAndOptions()

def main():
    results = sis.readResults(None, None, True)
    conn_types = {
        '0000000A': 'From system XYZ',
        '0000000B': 'Entered on the command line',
        '0000000C': 'from C',
        '0000000D': 'others'
    }
    for row in results:
        for key in row:
            if conn_types.get(key.strip()):
                row[conn_types[key]] = row[key]
                del row[key]

    sis.outputResults(results)
    return 0

try:
    main()
except Exception, e:
    import traceback
    stack =  traceback.format_exc()
    sis.generateErrorResults("Error '{e}'. {s}".format(e=e, s=stack))
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;You can place this script in &lt;CODE&gt;$SPLUNK_HOME/etc/apps/search/bin/&lt;/CODE&gt;, say &lt;CODE&gt;renamecolumns.py&lt;/CODE&gt;,&lt;BR /&gt;
and add/edit &lt;CODE&gt;$SPLUNK_HOME/etc/app/search/local/commands.conf&lt;/CODE&gt;:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[renamecolumns]
filename = renamecolumns.py
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;then search string:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;source=*test.log | timechart count by conn_type | renamecolumns
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Basically this reads the results and modify column names for you,&lt;BR /&gt;
and of course you can read file from csv if you'd like to.&lt;BR /&gt;
but if you have many events and/or large lookup, &lt;BR /&gt;
you might need to test which is faster - custom command or lookup&lt;/P&gt;

&lt;P&gt;HTH,&lt;BR /&gt;
Bill&lt;/P&gt;</description>
      <pubDate>Fri, 29 Apr 2016 11:00:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-a-search-string-dynamically-build-commands-and-then-run-them/m-p/225687#M66563</guid>
      <dc:creator>bchung_splunk</dc:creator>
      <dc:date>2016-04-29T11:00:01Z</dc:date>
    </item>
    <item>
      <title>Re: Can a search string dynamically build commands, and then run them?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-a-search-string-dynamically-build-commands-and-then-run-them/m-p/225688#M66564</link>
      <description>&lt;P&gt;Please accept an answer to help others in the future who may have a similar question.&lt;/P&gt;</description>
      <pubDate>Fri, 29 Apr 2016 12:12:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-a-search-string-dynamically-build-commands-and-then-run-them/m-p/225688#M66564</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2016-04-29T12:12:28Z</dc:date>
    </item>
    <item>
      <title>Re: Can a search string dynamically build commands, and then run them?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-a-search-string-dynamically-build-commands-and-then-run-them/m-p/225689#M66565</link>
      <description>&lt;P&gt;(Picks up dropped mic.) Thank you, @bchung. You just fast-forwarded my reality ;-). I knew I'd have to look at developing custom search commands in Python sooner or later, but you've handed to me on a plate an example that I can understand, use immediately, and customize. Thank you, thank you. I've accepted your answer based on this latest comment (I acknowledge this might be dodgy etiquette, but I am not going to ask you to submit this as a separate answer).&lt;/P&gt;</description>
      <pubDate>Mon, 02 May 2016 01:53:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-a-search-string-dynamically-build-commands-and-then-run-them/m-p/225689#M66565</guid>
      <dc:creator>Graham_Hanningt</dc:creator>
      <dc:date>2016-05-02T01:53:27Z</dc:date>
    </item>
    <item>
      <title>Re: Can a search string dynamically build commands, and then run them?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-a-search-string-dynamically-build-commands-and-then-run-them/m-p/225690#M66566</link>
      <description>&lt;P&gt;I'm still grateful for the pointer to &lt;CODE&gt;map&lt;/CODE&gt;, but decided to accept the answer from @bchung - not because of this original answer, but because of the example script he later added in a comment. (I'll take tips on how to better manage acceptance of answers in such a situation: I want to do the right thing; I don't want to offend anyone.)&lt;/P&gt;</description>
      <pubDate>Mon, 02 May 2016 02:00:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-a-search-string-dynamically-build-commands-and-then-run-them/m-p/225690#M66566</guid>
      <dc:creator>Graham_Hanningt</dc:creator>
      <dc:date>2016-05-02T02:00:31Z</dc:date>
    </item>
    <item>
      <title>Re: Can a search string dynamically build commands, and then run them?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-a-search-string-dynamically-build-commands-and-then-run-them/m-p/225691#M66567</link>
      <description>&lt;P&gt;@Graham_Hannington , I just converted the comment to an answer. Fell free to accept the correct one now.&lt;/P&gt;</description>
      <pubDate>Mon, 02 May 2016 02:22:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-a-search-string-dynamically-build-commands-and-then-run-them/m-p/225691#M66567</guid>
      <dc:creator>MuS</dc:creator>
      <dc:date>2016-05-02T02:22:32Z</dc:date>
    </item>
    <item>
      <title>Re: Can a search string dynamically build commands, and then run them?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-a-search-string-dynamically-build-commands-and-then-run-them/m-p/225692#M66568</link>
      <description>&lt;P&gt;@MuS, done. Thanks!&lt;/P&gt;</description>
      <pubDate>Mon, 02 May 2016 02:38:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-a-search-string-dynamically-build-commands-and-then-run-them/m-p/225692#M66568</guid>
      <dc:creator>Graham_Hanningt</dc:creator>
      <dc:date>2016-05-02T02:38:05Z</dc:date>
    </item>
    <item>
      <title>Re: Can a search string dynamically build commands, and then run them?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-a-search-string-dynamically-build-commands-and-then-run-them/m-p/225693#M66569</link>
      <description>&lt;P&gt;Glad to help &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;  please feel free to ask if you got any issue with custom commands!&lt;BR /&gt;
And thanks @MuS for converting this to an answer from comment.&lt;/P&gt;</description>
      <pubDate>Mon, 02 May 2016 03:33:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-a-search-string-dynamically-build-commands-and-then-run-them/m-p/225693#M66569</guid>
      <dc:creator>bchung_splunk</dc:creator>
      <dc:date>2016-05-02T03:33:02Z</dc:date>
    </item>
    <item>
      <title>Re: Can a search string dynamically build commands, and then run them?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-a-search-string-dynamically-build-commands-and-then-run-them/m-p/225694#M66570</link>
      <description>&lt;P&gt;The solution I came up with (mentioned in my previous comment) was flawed, because &lt;CODE&gt;xyseries&lt;/CODE&gt; does not produce the same "intelligent" X-axis labels as &lt;CODE&gt;timechart&lt;/CODE&gt;. @Jeremiah provided the following improved solution (in response to a &lt;A href="https://answers.splunk.com/answers/398911/how-do-you-make-output-from-xyseries-generate-the.html"&gt;different question&lt;/A&gt;&lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=my_log_type | bin _time | stats count by _time, conn_type | lookup connection_types.csv conn_type output description | timechart sum(count) as count by description
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 03 May 2016 06:39:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-a-search-string-dynamically-build-commands-and-then-run-them/m-p/225694#M66570</guid>
      <dc:creator>Graham_Hanningt</dc:creator>
      <dc:date>2016-05-03T06:39:54Z</dc:date>
    </item>
    <item>
      <title>Re: Can a search string dynamically build commands, and then run them?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-a-search-string-dynamically-build-commands-and-then-run-them/m-p/708454#M239580</link>
      <description>&lt;P&gt;I know an old question, but actually your idea works, the first part in the subsearch till "fields - ..." simply builds a table I use for field renaming, so that users only need to edit a lookup for renaming fields:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults 
| eval field1="some value", field2="another value" 
| rename
    [| makeresults 
    | eval mapping="field1:field_one field2:field_two" 
    | makemv delim=" " mapping 
    | mvexpand mapping 
    | rex field=mapping "(?&amp;lt;orig&amp;gt;[^:]+):(?&amp;lt;new&amp;gt;.*)" 
    | fields - _time, mapping 
    | eval rename_phrase=orig + " as " + "\"" + new + "\"" 
    | stats values(rename_phrase) as rename_phrases 
    | eval search=mvjoin(rename_phrases, ", ") 
    | fields search]&lt;/LI-CODE&gt;&lt;P&gt;But it can only build arguments, as seen that rename must be in the base search.&lt;/P&gt;&lt;P&gt;Maybe of use for somebody out there.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Jan 2025 19:29:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-a-search-string-dynamically-build-commands-and-then-run-them/m-p/708454#M239580</guid>
      <dc:creator>tom-t</dc:creator>
      <dc:date>2025-01-10T19:29:44Z</dc:date>
    </item>
  </channel>
</rss>

