Merging csv files

Post Reply
abonsey
Member
Posts: 142
Joined: Fri May 24, 2013 5:10 pm

Merging csv files

Post 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.
dkelly
TOP CONTRIBUTOR
Posts: 658
Joined: Mon Nov 29, 2010 8:45 pm
Location: Alpharetta GA USA
Contact:

Merging csv files

Post 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
dkelly
TOP CONTRIBUTOR
Posts: 658
Joined: Mon Nov 29, 2010 8:45 pm
Location: Alpharetta GA USA
Contact:

Merging csv files

Post 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();

Post Reply