Page 1 of 1

Special Chracters in file

Posted: 15 Nov 2018 08:56
by SIMMS7400
Folks -

I'm trying to parse the following file:
Update,Target Type,FP&A,Workforce,Real Estate,file1,file2
Update Legal Entity,TRUE,DEV,TRUE,TRUE,FALSE,REG1, test.csv
However, as you can imagine, I'm not able to parse the first row due to the special chracters. I think I need to toggle between delayexpansion but unable to be successful.

here is what I have so far - can someone assist?

Code: Select all

@echo off
setlocal enabledelayedexpansion
set /A elementNumber=0
for /F "tokens=*" %%L in (Process_Automation.csv) do (
	rem clear out elementNumber
	echo %%L
	call :parse %%L
	)

:parse
setlocal
set list=%*
echo !list!
for /F "tokens=1* delims=," %%f in ("!list!") do (
		set /A elementNumber+=1
    rem if the item exist
    if not %%g == "" call :parse %%g
)
endlocal
goto :eof
Thanks!

Re: Special Chracters in file

Posted: 15 Nov 2018 10:31
by Squashman
I do not see why you even need delayed expansion for that code. You are making a ton of NOT BEST PRACTICE coding mistakes, like not using quotes around your variables. You are missing an EXIT before the label as well.

Re: Special Chracters in file

Posted: 19 Nov 2018 09:14
by Sponge Belly
Hi SIMMS7400, :)

Please read the topic about Dave Benham’s excellent parseCSV Batch/JS hybrid utility, which should do what you want—and then some! ;)

- SB

PS: Please fix typo in subject line.