<?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 define the table column order in CLI searches in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-define-the-table-column-order-in-CLI-searches/m-p/236079#M70108</link>
    <description>&lt;P&gt;Thank you @woodcock for answering.&lt;/P&gt;

&lt;P&gt;By doing the searches again I found out the following:&lt;/P&gt;

&lt;P&gt;It works, but its not working as it supposed to be. &lt;BR /&gt;
&lt;CODE&gt;.\splunk.exe "sourcetype=wineventlog:system EventCode=20001 | fields _time, EventCode, ComputerName" -maxout 2 -output csv&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;and the output is:&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;"_serial","_time","_raw"&lt;BR /&gt;
...data...&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;its in fact csv but not the fields I want.&lt;BR /&gt;
I also figured out that using Message is not good for csv because it has many linefeeds.&lt;/P&gt;

&lt;P&gt;It works fine if and only if I run the search with the &lt;STRONG&gt;table&lt;/STRONG&gt; command like this:&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;.\splunk.exe "sourcetype=wineventlog:system EventCode=20001 | table _time, EventCode, ComputerName | fields _time, EventCode, ComputerName" -maxout 2 -output csv&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;but again the order is different to what i defined. The order is: &lt;CODE&gt;EventCode, _time, ComputerName&lt;/CODE&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 17 Nov 2015 10:13:23 GMT</pubDate>
    <dc:creator>ciir</dc:creator>
    <dc:date>2015-11-17T10:13:23Z</dc:date>
    <item>
      <title>How to define the table column order in CLI searches</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-define-the-table-column-order-in-CLI-searches/m-p/236077#M70106</link>
      <description>&lt;P&gt;Hi @ all,&lt;/P&gt;

&lt;P&gt;I'm using this search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=wineventlog:system (EventCode=20001) | table _time, EventCode, ComputerName, Message | sort _time desc
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If invoked in the Splunk GUI, the table has the fields/columns in the order which is defined within the search using the &lt;CODE&gt;table&lt;/CODE&gt; command.&lt;/P&gt;

&lt;P&gt;But if the search is invoked within the Windows cmd.exe or Powershell, the order of the fields is:&lt;BR /&gt;
&lt;CODE&gt;EventCode, _time, Message, ComputerName&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;I've found a similar question &lt;A href="https://answers.splunk.com/answers/204709/fields-order-when-using-splunk-search-in-command-l.html"&gt;here&lt;/A&gt; (&lt;A href="https://answers.splunk.com/answers/204709/fields-order-when-using-splunk-search-in-command-l.html"&gt;https://answers.splunk.com/answers/204709/fields-order-when-using-splunk-search-in-command-l.html&lt;/A&gt; ), which tells us to use &lt;CODE&gt;fields field1, field2, ...&lt;/CODE&gt;. However, by using the &lt;CODE&gt;fields&lt;/CODE&gt;, command I can't output my results as CSV. I also tried to rename the fields, but still no luck and the order remains the same. &lt;/P&gt;

&lt;P&gt;Any idea how I can explicitly define the order of my columns within a table using a CLI search?&lt;/P&gt;

&lt;P&gt;thanks in advance&lt;BR /&gt;
-ciir&lt;/P&gt;</description>
      <pubDate>Mon, 16 Nov 2015 10:06:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-define-the-table-column-order-in-CLI-searches/m-p/236077#M70106</guid>
      <dc:creator>ciir</dc:creator>
      <dc:date>2015-11-16T10:06:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to define the table column order in CLI searches</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-define-the-table-column-order-in-CLI-searches/m-p/236078#M70107</link>
      <description>&lt;P&gt;Show us the command and error when using &lt;CODE&gt;fields&lt;/CODE&gt; with &lt;CODE&gt;outputcsv&lt;/CODE&gt;; it should work fine.&lt;/P&gt;</description>
      <pubDate>Mon, 16 Nov 2015 21:55:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-define-the-table-column-order-in-CLI-searches/m-p/236078#M70107</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2015-11-16T21:55:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to define the table column order in CLI searches</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-define-the-table-column-order-in-CLI-searches/m-p/236079#M70108</link>
      <description>&lt;P&gt;Thank you @woodcock for answering.&lt;/P&gt;

&lt;P&gt;By doing the searches again I found out the following:&lt;/P&gt;

&lt;P&gt;It works, but its not working as it supposed to be. &lt;BR /&gt;
&lt;CODE&gt;.\splunk.exe "sourcetype=wineventlog:system EventCode=20001 | fields _time, EventCode, ComputerName" -maxout 2 -output csv&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;and the output is:&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;"_serial","_time","_raw"&lt;BR /&gt;
...data...&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;its in fact csv but not the fields I want.&lt;BR /&gt;
I also figured out that using Message is not good for csv because it has many linefeeds.&lt;/P&gt;

&lt;P&gt;It works fine if and only if I run the search with the &lt;STRONG&gt;table&lt;/STRONG&gt; command like this:&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;.\splunk.exe "sourcetype=wineventlog:system EventCode=20001 | table _time, EventCode, ComputerName | fields _time, EventCode, ComputerName" -maxout 2 -output csv&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;but again the order is different to what i defined. The order is: &lt;CODE&gt;EventCode, _time, ComputerName&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Nov 2015 10:13:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-define-the-table-column-order-in-CLI-searches/m-p/236079#M70108</guid>
      <dc:creator>ciir</dc:creator>
      <dc:date>2015-11-17T10:13:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to define the table column order in CLI searches</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-define-the-table-column-order-in-CLI-searches/m-p/236080#M70109</link>
      <description>&lt;P&gt;Is there maybe a default value for the order, when using Web Search that doesn't affect the CLI search? Have you tried &lt;CODE&gt;.\splunk.exe "sourcetype=wineventlog:system EventCode=20001 | fields + _time, EventCode, ComputerName" -maxout 2 -output csv&lt;/CODE&gt; (added a &lt;CODE&gt;+&lt;/CODE&gt; between &lt;CODE&gt;fields&lt;/CODE&gt; and &lt;CODE&gt;_time&lt;/CODE&gt;)&lt;/P&gt;</description>
      <pubDate>Tue, 17 Nov 2015 10:53:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-define-the-table-column-order-in-CLI-searches/m-p/236080#M70109</guid>
      <dc:creator>Sebastian2</dc:creator>
      <dc:date>2015-11-17T10:53:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to define the table column order in CLI searches</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-define-the-table-column-order-in-CLI-searches/m-p/236081#M70110</link>
      <description>&lt;P&gt;Thank your very much @Sebastian2 the added &lt;CODE&gt;+&lt;/CODE&gt; does the trick!&lt;BR /&gt;
But only if it is used the following way:&lt;BR /&gt;
&lt;CODE&gt;.\splunk.exe "sourctype="wineventlog:system EventCode=20001 | table _time, EventCode, ComputerName | fields + _time, EventCode, ComputerName" -maxout 2&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Nov 2015 11:42:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-define-the-table-column-order-in-CLI-searches/m-p/236081#M70110</guid>
      <dc:creator>ciir</dc:creator>
      <dc:date>2015-11-17T11:42:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to define the table column order in CLI searches</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-define-the-table-column-order-in-CLI-searches/m-p/236082#M70111</link>
      <description>&lt;P&gt;Great! Maybe you should consider a bug-report with detailed information for the Splunk Team; I'm sure that doesn't work as intended&lt;/P&gt;</description>
      <pubDate>Tue, 17 Nov 2015 11:58:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-define-the-table-column-order-in-CLI-searches/m-p/236082#M70111</guid>
      <dc:creator>Sebastian2</dc:creator>
      <dc:date>2015-11-17T11:58:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to define the table column order in CLI searches</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-define-the-table-column-order-in-CLI-searches/m-p/236083#M70112</link>
      <description>&lt;P&gt;I discovered that as soon as you add &lt;CODE&gt;-output csv&lt;/CODE&gt; the order of the fields are changed. &lt;/P&gt;</description>
      <pubDate>Tue, 17 Nov 2015 12:37:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-define-the-table-column-order-in-CLI-searches/m-p/236083#M70112</guid>
      <dc:creator>ciir</dc:creator>
      <dc:date>2015-11-17T12:37:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to define the table column order in CLI searches</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-define-the-table-column-order-in-CLI-searches/m-p/236084#M70113</link>
      <description>&lt;P&gt;Try &lt;CODE&gt;| fields keepcolorder=t&lt;/CODE&gt;.&lt;/P&gt;</description>
      <pubDate>Tue, 17 Nov 2015 17:49:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-define-the-table-column-order-in-CLI-searches/m-p/236084#M70113</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2015-11-17T17:49:22Z</dc:date>
    </item>
  </channel>
</rss>

