I have a CSV file which looks like:
height, comment, name
152, he was late, for example, on Tuesday, Fred
162, , Sam
I cannot parse this file because it includes a variable number of unenclosed commas in the comment field (but no other fields). I would like to fix the file using awk (which is very new to me) so that the commas in the second field become semi-colons:
height, comment, name
152, he was late; for example; on Tuesday, Fred
162, , Sam
(Enclosing the entire field in quotes will not solve my problem because my CSV parser does not understand quotes.)
So far I am looking at using NF to work out the number of unenclosed commas and then replacing them using gsub with an unpleasant regex, but I feel I should be able to leverage awk to write a more readable program and I am not sure NF behaves this way.
Essentially just a brute-force solution, but fairly easy to understand. Invoke with
The awk file.