<?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 convert raw csv data into table format in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-convert-raw-csv-data-into-table-format/m-p/691261#M235402</link>
    <description>&lt;P&gt;I assume that each CSV file is ingested as one source. &amp;nbsp;In that case, a search by source would retrieve all entries in that file. &amp;nbsp;All you need is to add back headers. &amp;nbsp;But keep in mind:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;You cannot get the original order of headers back. &amp;nbsp;Headers will be in ASCII order.&lt;/LI&gt;&lt;LI&gt;You cannot get the original row order back. &amp;nbsp;Rows will be in matrix ASCII order.&lt;/LI&gt;&lt;LI&gt;If your original headers contain patterns incompatible with Splunk header standards, those headers will be changed to Splunk headers.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;Here, I will use an ordinary CSV as example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;c, b, a
1,2,3
4,,5
,6,7
8,,&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can use the following&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=myindex sourcetype=mysourcetype source=mycsv
| tojson
| appendpipe
    [foreach *
        [eval header = mvappend(header, "&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;")]]
| fields header
| where isnotnull(header)
| stats values(header) as header values(_raw) as json
| foreach json mode=multivalue
    [ eval csv = mvappend(csv, "\"" . mvjoin(mvmap(header, if(isnull(spath(&amp;lt;&amp;lt;ITEM&amp;gt;&amp;gt;, header)),"", spath(&amp;lt;&amp;lt;ITEM&amp;gt;&amp;gt;, header))), "\",\"") . "\"")]
| eval csv = mvjoin(header, ",") . "
" . mvjoin(csv, "
")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The mock data will give a csv field with the following value:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;a,b,c
"3","2","1"
"5","","4"
"7","6",""
"","","8"&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As explained above, much depends on the original CSV. &amp;nbsp;For example,&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;I took precaution to quote each "cell" even though your original CSV may not use quotation marks.&lt;/LI&gt;&lt;LI&gt;I did not quote headers, even though your original CSV may have used quotation marks.&lt;/LI&gt;&lt;LI&gt;With certain column names and/or cell values, additional coding is needed.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;You can play with the following data emulation and compare with real data.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults format=csv data="c, b, a
1,2,3
4,,5
,6,7
8,,"
| foreach *
    [eval _raw = if(isnull(_raw), "", _raw . ",") . if(isnull(&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;), "", &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;)]
``` the above emulates
index=myindex sourcetype=mysourcetype source=mycsv
```&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 21 Jun 2024 08:27:27 GMT</pubDate>
    <dc:creator>yuanliu</dc:creator>
    <dc:date>2024-06-21T08:27:27Z</dc:date>
    <item>
      <title>How to convert raw csv data into table format</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-convert-raw-csv-data-into-table-format/m-p/691052#M235351</link>
      <description>&lt;P&gt;Hi Team,&lt;/P&gt;&lt;P&gt;We have onboarded csv data into Splunk and each row in csv is ingested into _raw field . I need to bring this back to tabular format and run query against it. Kindly assist.&lt;/P&gt;&lt;P&gt;Note- We are not supposed to add csv files directly into the Splunk via "Add inputs" option.&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Sid&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jun 2024 03:23:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-convert-raw-csv-data-into-table-format/m-p/691052#M235351</guid>
      <dc:creator>Splunk_sid</dc:creator>
      <dc:date>2024-06-19T03:23:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert raw csv data into table format</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-convert-raw-csv-data-into-table-format/m-p/691055#M235352</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/260328"&gt;@Splunk_sid&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;gt;&amp;gt;&amp;gt; Note- We are not supposed to add csv files directly into the Splunk via "Add inputs" option.&lt;BR /&gt;so you have onboarded the CSV file or not yet?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;if you have onboarded the CSV file, then, just use the table command..&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=yourCSVindex source=someSource sourcetype=some | table *&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jun 2024 04:29:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-convert-raw-csv-data-into-table-format/m-p/691055#M235352</guid>
      <dc:creator>inventsekar</dc:creator>
      <dc:date>2024-06-19T04:29:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert raw csv data into table format</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-convert-raw-csv-data-into-table-format/m-p/691057#M235353</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/80737"&gt;@inventsekar&lt;/a&gt;&amp;nbsp;There are multiple csv files from which data gets loaded into Splunk. So, the _raw will have column headers and other rows for each file. All I need is to convert back into rows and columns format just like what we see in csv. "table" command will not serve the purpose for my scenario.&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jun 2024 05:47:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-convert-raw-csv-data-into-table-format/m-p/691057#M235353</guid>
      <dc:creator>Splunk_sid</dc:creator>
      <dc:date>2024-06-19T05:47:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert raw csv data into table format</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-convert-raw-csv-data-into-table-format/m-p/691058#M235354</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/260328"&gt;@Splunk_sid&lt;/a&gt;&amp;nbsp;.. We may need more details from your side.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Your current search query, what table format you are looking for, ...&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jun 2024 05:51:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-convert-raw-csv-data-into-table-format/m-p/691058#M235354</guid>
      <dc:creator>inventsekar</dc:creator>
      <dc:date>2024-06-19T05:51:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert raw csv data into table format</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-convert-raw-csv-data-into-table-format/m-p/691144#M235370</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/80737"&gt;@inventsekar&lt;/a&gt;&amp;nbsp;We have onboarded the data coming from csv files in inputs.conf as below and the data is loaded every day as new csv is created with date stamp.&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;[monitor:&amp;lt;path&amp;gt;/file_*.csv]&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;disabled&lt;/SPAN&gt;&lt;SPAN&gt; = false&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;sourcetype&lt;/SPAN&gt;&lt;SPAN&gt; = &amp;lt;sourcetype&amp;gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;index&lt;/SPAN&gt;&lt;SPAN&gt;=&amp;lt;index&amp;gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;With this config, we are getting the data into splunk and each row in csv is loaded as separate event. &lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Query:&amp;nbsp; index=&amp;lt;index&amp;gt; sourcetype=&amp;lt;sourcetype&amp;gt;.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;All we need is to see the data similar to csv ie. we need to have a single line header and corresponding data for those columns (just how we see when we load the csv from Add inputs via Splunk GUI).&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;As of now, events are like as shown below and it repeats every day for new csv files&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;TABLE width="332px"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="117.675px"&gt;&lt;SPAN class=""&gt;&lt;SPAN&gt;6/17/24&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;3:07:26.000 AM&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD width="213.525px"&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;SPAN class=""&gt;col1&lt;/SPAN&gt;,&lt;SPAN class=""&gt;col2&lt;/SPAN&gt;,col3,col4,col5,col6&amp;nbsp;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;P&gt;&lt;SPAN&gt;host = &amp;lt;host&amp;gt;&lt;BR /&gt;source =&amp;lt;source&amp;gt;&lt;BR /&gt;sourcetype =&amp;lt;sourcetype&amp;gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="117.675px"&gt;&lt;SPAN class=""&gt;&lt;SPAN&gt;6/17/24&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;3:07:26.000 AM&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD width="213.525px"&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;SPAN class=""&gt;data1&lt;/SPAN&gt;,data&lt;SPAN class=""&gt;2&lt;/SPAN&gt;,data3,data4,data5,data6&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;P&gt;&lt;SPAN&gt;host = &amp;lt;host&amp;gt;&lt;BR /&gt;source =&amp;lt;source&amp;gt;&lt;BR /&gt;sourcetype =&amp;lt;sourcetype&amp;gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;We need the output in below format when we run query:&lt;/P&gt;&lt;TABLE width="383px"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="40px"&gt;col1&lt;/TD&gt;&lt;TD width="40px"&gt;col2&lt;/TD&gt;&lt;TD width="40px"&gt;col3&lt;/TD&gt;&lt;TD width="55px"&gt;col4&lt;/TD&gt;&lt;TD width="104px"&gt;col5&lt;/TD&gt;&lt;TD width="104px"&gt;col6&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="40px"&gt;data1&lt;/TD&gt;&lt;TD width="40px"&gt;data2&lt;/TD&gt;&lt;TD width="40px"&gt;data3&lt;/TD&gt;&lt;TD width="55px"&gt;data4&lt;/TD&gt;&lt;TD width="104px"&gt;data5&lt;/TD&gt;&lt;TD width="104px"&gt;data6&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Regards,&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Sid&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Thu, 20 Jun 2024 04:58:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-convert-raw-csv-data-into-table-format/m-p/691144#M235370</guid>
      <dc:creator>Splunk_sid</dc:creator>
      <dc:date>2024-06-20T04:58:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert raw csv data into table format</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-convert-raw-csv-data-into-table-format/m-p/691261#M235402</link>
      <description>&lt;P&gt;I assume that each CSV file is ingested as one source. &amp;nbsp;In that case, a search by source would retrieve all entries in that file. &amp;nbsp;All you need is to add back headers. &amp;nbsp;But keep in mind:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;You cannot get the original order of headers back. &amp;nbsp;Headers will be in ASCII order.&lt;/LI&gt;&lt;LI&gt;You cannot get the original row order back. &amp;nbsp;Rows will be in matrix ASCII order.&lt;/LI&gt;&lt;LI&gt;If your original headers contain patterns incompatible with Splunk header standards, those headers will be changed to Splunk headers.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;Here, I will use an ordinary CSV as example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;c, b, a
1,2,3
4,,5
,6,7
8,,&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can use the following&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=myindex sourcetype=mysourcetype source=mycsv
| tojson
| appendpipe
    [foreach *
        [eval header = mvappend(header, "&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;")]]
| fields header
| where isnotnull(header)
| stats values(header) as header values(_raw) as json
| foreach json mode=multivalue
    [ eval csv = mvappend(csv, "\"" . mvjoin(mvmap(header, if(isnull(spath(&amp;lt;&amp;lt;ITEM&amp;gt;&amp;gt;, header)),"", spath(&amp;lt;&amp;lt;ITEM&amp;gt;&amp;gt;, header))), "\",\"") . "\"")]
| eval csv = mvjoin(header, ",") . "
" . mvjoin(csv, "
")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The mock data will give a csv field with the following value:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;a,b,c
"3","2","1"
"5","","4"
"7","6",""
"","","8"&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As explained above, much depends on the original CSV. &amp;nbsp;For example,&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;I took precaution to quote each "cell" even though your original CSV may not use quotation marks.&lt;/LI&gt;&lt;LI&gt;I did not quote headers, even though your original CSV may have used quotation marks.&lt;/LI&gt;&lt;LI&gt;With certain column names and/or cell values, additional coding is needed.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;You can play with the following data emulation and compare with real data.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults format=csv data="c, b, a
1,2,3
4,,5
,6,7
8,,"
| foreach *
    [eval _raw = if(isnull(_raw), "", _raw . ",") . if(isnull(&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;), "", &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;)]
``` the above emulates
index=myindex sourcetype=mysourcetype source=mycsv
```&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Jun 2024 08:27:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-convert-raw-csv-data-into-table-format/m-p/691261#M235402</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2024-06-21T08:27:27Z</dc:date>
    </item>
  </channel>
</rss>

