I've been working through examples on find and replace for a CSV file but I can't seem to get anything to work and I am hoping for some help. Running this on windows.
I have to deal with a poorly-formatted CSV file where commas and double-quotes are all in the wrong place.
Sample CSV:
Device,Block,Block,Block
Value,Power,Current(Best", Set," Ex),Power
Data, 3, 4, 3
I want to replace '", ' to '_' before processing. The goal being that Current(Best_Set_Ex) will be in one column.
Perl script (updated): sanitize.pl
use warnings;
use strict;
while (<>) {
s/," /_/g;
s/", /_/g;
print ;
}
Command:
perl -p -i.orig sanitize.pl perltest.csv
Error: Can't open perl script "orig": No such file or directory
[io.file]::readalltext("p:\pstest.csv").replace('", ',"_") | Out-File "P:\psreplaced.csv" -enconding ascii -force