Sidebar

Can I convert a Comma Separated File (CSV) to a Pipe Delimited File?

0 votes
397 views
asked Nov 30, 2016 by brandon-w-8204 (33,270 points)
edited Nov 30, 2016 by brandon-w-8204

Here is my source csv:

533837,2250666,0195772,80053,Comprehensive Metabolic Panel,4440408,15.5400,20161010000000,3710011202,20161011000000,2282312,100.0000,13

I need it to look like this.

533837|2250666|0195772|80053|Comprehensive Metabolic Panel|4440408|15.5400|20161010000000|3710011202|20161011000000|2282312|100.0000|13
 

1 Answer

0 votes

You can accomplish this using the following code.

// set message to Pipe delimited file (without header row)
message = qie.createCSVMessage(false, '"', '|', '', false);

// or, set message to Pipe delimited file (with header row)
//message = qie.createCSVMessage(false, '"', '|', '', true);

//Convert via a regular expression
message.setNode('/', source.getNode('/').replaceAll('(,)(?=(?:[^"]|"[^"]*")*$)', '|'));

answered Nov 30, 2016 by brandon-w-8204 (33,270 points)
edited Nov 30, 2016 by brandon-w-8204
...