I have a CSV file that is comma-delimited, but the last field in each line is double-quoted and may contain commas within the quotes. I need to have all the commas replaced with pipes (like | ) EXCEPT for the ones within the quoted field at the end of each line.
Example of a line from the file:
2,1,24,Bourne,Jason,,06-01-1973,M,Ned,,Grove,,College Rd,72,1,01-10-2012,Null,85,S,"notes go here, and may contain commas."
I've run the following Powershell script but found that it replaces even the commas within the quotes at the end of the line:
(Get-Content c:\input.csv)
| % {$_ -replace ',', "|"}
| out-file -FilePath c:\output.csv -Force -Encoding ascii
I've been struggling for a couple hours now trying to come up with a regex to only replace the first 19 commas, but not much success so far. My experience with regex is very limited so this is a learning experience for me. Any help is greatly appreciated!
"then running your replace on that?