Parsing csv and printing data in batch script

157 views Asked by At

I have this in my trim_csv.bat (I intend to trim trailing spaces of every entry in the csv).

FOR /F "delims=;" %i IN (csv_exports\account.csv) DO @echo %i (I have also tried enclosing the path with quotes, no difference.)

Executing it through cmd results to:

i was unexpected at this time.

What do I misunderstand? I tried following syntax coming from HELP FOR but I feel like that is something simple that I just can't see.

PS: It's quite new in batch scripting as you can imagine.

1

There are 1 answers

0
Renat On BEST ANSWER

If the code is going to be a part of a bat file, percents should be escaped as %i -> %%i:

FOR /F "delims=;" %%i IN (csv_exports\account.csv) DO @echo %%i