I wrote a script that replaces the semicolon delimiter in a text file to commas, but it also puts quotes around the text of the 9th column since the 9th column contains commas. When I output to the new text file it process very slow, takes maybe 4-5 minutes, the text file that it is reading from is 50MB. Is there faster way or more efficient way to do this? Here is my FOR loop:
FOR /f "usebackq tokens=1-9* delims=;" %%a IN ("%FILENAME%") DO (
SET C10=%%j
ECHO(%%a,%%b,%%c,%%d,%%e,%%f,%%g,%%h,"%%i",!C10:;=,! >> "%MYPATH%\Filename %MMDDYYYY%.csv")
or should I just learn python.....
Thank you.
解决方案
One thing that will make the script run "faster" is to avoid opening and closing the output file for each write operation
>> "%MYPATH%\Filename %MMDDYYYY%.csv" (
FOR /f "usebackq tokens=1-9* delims=;" %%a IN ("%FILENAME%") DO (
SET C10=%%j
ECHO(%%a,%%b,%%c,%%d,%%e,%%f,%%g,%%h,"%%i",!C10:;=,!
)
)
Instead of redirecting each line, redirect the full for command.