You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by sarfaraj <sa...@gmail.com> on 2013/03/15 12:53:57 UTC

How to escape commas(,) in CSV file

Hi,

I have csv file with following data

"ID","NAME","ADDR"
"1","Sarfaraj Sayyad","Pune,India"

I am using camel csv component here and generate the resultant csv's 
But what happened it created four columns

1,Sarfaraj Sayyad,Pune,India

It should be like 1,Sarfaraj Sayyad,"Pune,India"

Can some one tell me how to escape comma in camel csv component.




--
View this message in context: http://camel.465427.n5.nabble.com/How-to-escape-commas-in-CSV-file-tp5729241.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: How to escape commas(,) in CSV file

Posted by Henryk Konsek <he...@gmail.com>.
> Worked :)
> Thanks *Henryk Konsek*

I'm more than happy that I was useful :) .

Best regards.

--
Henryk Konsek
http://henryk-konsek.blogspot.com

Re: How to escape commas(,) in CSV file

Posted by sarfaraj <sa...@gmail.com>.
Worked :)

Thanks *Henryk Konsek*



--
View this message in context: http://camel.465427.n5.nabble.com/How-to-escape-commas-in-CSV-file-tp5729241p5729584.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: How to escape commas(,) in CSV file

Posted by Henryk Konsek <he...@gmail.com>.
> How do we create the csv with double quotes using camel csv component ? is
> it possible ?

Actually I've already explained this in my previous post. Please do
kindly refer to it. :)

Best regards.

--
Henryk Konsek
http://henryk-konsek.blogspot.com

Re: How to escape commas(,) in CSV file

Posted by sarfaraj <sa...@gmail.com>.
In our input csv I am getting the data with double quotes (" "). like below

"ID","NAME","ADDR" 
"1","Sarfaraj Sayyad","Pune,India" 

but camel csv component created without double quotes.  (1,Sarfaraj
Sayyad,Pune,India )

How do we create the csv with double quotes using camel csv component ? is
it possible ?

/Sarfaraj



--
View this message in context: http://camel.465427.n5.nabble.com/How-to-escape-commas-in-CSV-file-tp5729241p5729527.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: How to escape commas(,) in CSV file

Posted by Henryk Konsek <he...@gmail.com>.
Hi,

> Can some one tell me how to escape comma in camel csv component.

Actually CSV component doesn't conform Camel standards in 100%. First
of all it depends on the project with no stable release [1] and
basically no documentation. It is even hard to get the sources of the
CSV library jar used by Camel, as it is some kind of snapshot taken
from the trunk at certain point of time.

I personally don't know how to escape CSV with our component, so I
process my messages with StringEscapeUtils.html#escapeCsv [2] method
from Apache Commons before passing them to the CSV data format.

Actually I created camel-csv-simple data format which doesn't depend
on Commons CSV project. It works similarly to camel-csv but doesn't
require any additional dependencies and handles CSV escaping
out-of-the-box by default. I  guess I should have committed it some
time ago. I'll try to submit it to trunk after some discussion with
fellow Camel riders.

In the meantime StringEscapeUtils.html#escapeCsv could be a way to go :) .

Best regards.

[1] http://commons.apache.org/proper/commons-csv/downloads.html
[2] http://commons.apache.org/proper/commons-lang/javadocs/api-3.1/org/apache/commons/lang3/StringEscapeUtils.html#escapeCsv(java.lang.String)

--
Henryk Konsek
http://henryk-konsek.blogspot.com