I have a 200,000+ line file that I need to update.
My issue is that I need to use commas to separate the fields; however in the original file there are commas placed in the "comment section." The comment section is delimited by ""
. Not all lines have this comment field populated and it may not contain any commas.
So when using awk
with -F,
my columns are skewed due to the commas in the comment section.
Here is an example of a line in my file:
XX,YYY,ZZZ,XXXX,Y,,,QQQQ,AAAA,BBBBB,,,XXX,YYY,,,,,ZZZ,QQ,AAAAAA,YY,ZZZZZZZZ,"Zona Industriale, Via Golgi snc",QQ.ZZZZZZZZ,QQ.ZZZZZZ,31.5,2,0,MACRO,#N/A
In the above I need to replace:
"Zona **Industriale, Via Golgi snc"
with
"Zona **Industriale Via Golgi snc"
So long story short the ,
needs to be removed between the ""
s in the line above and in about 70% of the existing file.
awk
on a CSV file is your goal, then see this answer about using GNU awk and FPAT to recognize quoted fields even if they include commas.