I have an input file in CSV format. There are some fields enclosed in double quotes that have a comma in them. Here is the sample row
123,"ABC, DEV 23",345,534.202,NAME
I need to remove all the commas that are not occurring within the double quotes by a ~
,
so the output should be like this:
123~"ABC, DEV 23"~345~534.202~NAME
I have tried this, but it gives me the reverse output:
awk -F '"' -v OFS='' '{ for (i=0; i<= NF; ++i) gsub(",","~",$i) } 1' test.txt
123,ABC~ DEV 23,345,534.202,NAME