Special Chracters in file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
SIMMS7400
Posts: 546
Joined: 07 Jan 2016 07:47

Special Chracters in file

#1 Post by SIMMS7400 » 15 Nov 2018 08:56

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!

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Special Chracters in file

#2 Post by Squashman » 15 Nov 2018 10:31

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.

Sponge Belly
Posts: 231
Joined: 01 Oct 2012 13:32
Location: Ireland
Contact:

Re: Special Chracters in file

#3 Post by Sponge Belly » 19 Nov 2018 09:14

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.

Post Reply