Page 1 of 1
Merging csv files
Posted: Tue May 28, 2013 8:22 pm
by abonsey
Is it possible to read/merge multiple csv files into on file and then sort on a column basis?
Any guidance or sample flow greatly appreciated.
Merging csv files
Posted: Tue May 28, 2013 9:28 pm
by dkelly
We have implemented several custom Javascript flow elements to perform similar operations on CSV files for our customers. Complexity depends on whether the files have the same number of columns and they are in the same order.
Dwight Kelly
Apago, Inc.
dkelly@apago.com
Merging csv files
Posted: Tue May 28, 2013 9:41 pm
by dkelly
Here's the Javascript basics to read a basic CSV file.
var csvFile = new File( csvFilename );
if (csvFile.exists == false) {
job.log(cLogError, "Could not open CSV file: " + csvFilename);
return false;
}
csvFile.open(File.ReadOnly);
var hdrline = csvFile.readLine();
var separator = ",";
do {
var line = csvFile.readLine();
var i, recTokens = line.split(separator);
for (i=0; i<recTokens.length; i++)
job.log(cLogInfo, recTokens);
} while (!csvFile.eof);
csvFile.close();