0

I have a CSV file which has 3 columns. I'm trying to extract the value in the column third and remove quotes from values and write it into another csv. The columns are seperated with "," so I select the column third with

for /f "tokens=3 delims=, " %%a in (example.csv) do (
 echo %aa >> example2.csv
)

It works perfect but the data comes with quotes like "5884" so I tried

for /f "tokens=3 delims=, " %%a in (example.csv) do (
    set /A tirnak=%%a
   echo %%tirnak >> example2.csv
)

When I "set /A tirnak=%%a" output value has no quotes in CMD and I can make it echo in a text file, but when I use it in the loop output in the file is

ECHO is on.

I tried echo %tirnak%, echo %tirnak, echo %%tirnak but the output in the file is either ECHO is on, empty, sth like %tirnak etc. How can I do that? Thank you.

  • [enable delayed expansion](https://stackoverflow.com/q/22278456/995714) and use `!tirnak!` – phuclv Feb 15 '18 at 00:47
  • Or just avoid using multi-line code blocks all together: `do call :SetTirnak %%a`, then define a label `SetTirnak` add your code there and terminate it with an `exit /b 0`. Don't forget to add an `exit /b 0` after the for loop though. – jwdonahue Feb 15 '18 at 00:53
  • You should consider reading the help file for the commands you are trying to use. – Squashman Feb 15 '18 at 02:35

1 Answers1

1

Using your chosen Tokens and Delims, this looks like what you need:

For /F "UseBackQ Tokens=3 Delims=, " %%A In ("example.csv") Do (
    Echo %%~A)>>"example2.csv"
Compo
  • 36,585
  • 5
  • 27
  • 39
  • Absolutely! OP: please cut-and-paste code - don't rewrite it. Your code line `echo %aa >> example2.csv` could not give you the results you claim. `echo %%a >> example2.csv` - now *that* I'd believe. – Magoo Feb 15 '18 at 07:38