windowsbatch-filecmd

Read lines with blank spaces from a file using batch


I'm trying to read each line from a text file using batch.

The lines inside the file has some blank spaces, so this is an example of the input:

This is the first line
This is the second line
...

I'm using the following source code

FOR /f %%a in ("%1") do (
    @echo %%a
)
goto:eof

The output is the follwing:

This
This
...

I have read the following entry in Stack Overflow but is doesn't solve my issue. Batch : read lines from a file having spaces in its path


Solution

  • try this.

    FOR /f "tokens=* delims=,"  %%a in ('type "%1"') do (
        @echo %%a
    )