Link to home
Start Free TrialLog in
Avatar of PearlJamFanatic
PearlJamFanatic

asked on

remove double quotes from csv file using opencsv

I need to process/clean a csv file. The csv file looks like below
sep=,
"Symbol","Date","Expiry","Option Type","Strike Price","Open","High","Low","Close","LTP","Settle Price","No. of contracts","Turnover in Lacs","Premium Turnover in Lacs","Open Int","Change in OI","Underlying Value"
"STOCKA","03-Oct-2017","30-Nov-2017","PE","11450","0","0","0","1309.85","0","1477.35","0","0","0","0","0","9859.5"
"STOCKA","03-Oct-2017","30-Nov-2017","PE","11500","0","0","0","1338.55","0","1526.75","0","0","0","0","0","9859.5"
"STOCKA","03-Oct-2017","30-Nov-2017","PE","11550","0","0","0","1304.05","0","1576.15","0","0","0","0","0","9859.5"
"STOCKA","03-Oct-2017","30-Nov-2017","PE","11600","0","0","0","1352.8","0","1625.55","0","0","0","0","0","9859.5"

Open in new window

I am using open csv. How do i remove the double quotes in the data so that it looks like below.

sep=,
Symbol , Date, Expiry, Option Type, Strike Price, Open, High, Low, Close, LTP, Settle Price, No. of contracts, Turnover in Lacs, Premium Turnover in Lacs, Open Int, Change in OI, Underlying Value
STOCKA , 03-Oct-2017 , 30-Nov-2017 , PE , 11450 , 0, 0, 0, 1309.85, 0, 1477.35, 0, 0, 0, 0, 0, 9859.5
STOCKB, 03-Oct-2017 , 30-Nov-2017 , PE , 11450 , 0, 0, 0, 1301.35, 0, 1477.35, 0, 0, 0, 0, 0, 9899.5
STOCKC , 03-Oct-2017 , 30-Nov-2017 , PE , 11450 , 0, 0, 0, 1309.95, 0, 1477.35, 0, 0, 0, 0, 0, 9849.5
STOCKD , 03-Oct-2017 , 30-Nov-2017 , PE , 11450 , 0, 0, 0, 1300.05, 0, 1477.35, 0, 0, 0, 0, 0, 9859.5

Open in new window

Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Well, are you 100% certain that removing the double quotes would never leave you with a problem? If so, then you don't need a special library. Java Reader/Writer would do it
Command line Unix:

tr -d '"' <old.csv>new.csv

Open in new window


otoh, if you're not 100% certain (can one ever be?) then the proper way would be to use the library's escapement to remove the quotes safely
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.