Combine csv files of same structure
There are multiple csv files of same structure in a directory. These files have similar prefixes:
stock_301500.csv |
stock_320688.csv |
CODE,DT,OP,CL 301500,2023-06-02,71,67.8 301500,2023-06-05,79.35,72.61 301500,2023-06-06,75.8,77.65 |
CODE,DT,OP,CL 320688,2023-06-02,33,32 320688,2023-06-05,28.37,30.23 320688,2023-06-06,27.19,28.54 |
Use Java to combine the csv files as a single file.
Here is the SPL code:
=directory@p("D:\\data\\stock_*.csv").(file("result.csv").export@tca(T(~)))
directory@p lists file names with full paths according to the wild character. export@tca writes the two-dimensional table to a file; @t option means exporting column names; @c enables using the csv format; an d @a means append-write.
SPL also supports SQL syntax. The following code will get the same result.
$select * into result1.csv from D:\\data\\stock_*.csv
Read How to Call a SPL Script in Java to find how to integrate SPL into a Java application.
SPL Official Website 👉 https://www.scudata.com
SPL Feedback and Help 👉 https://www.reddit.com/r/esProcSPL
SPL Learning Material 👉 https://c.scudata.com
SPL Source Code and Package 👉 https://github.com/SPLWare/esProc
Discord 👉 https://discord.gg/cFTcUNs7
Youtube 👉 https://www.youtube.com/@esProc_SPL