Santhosh Ram
Santhosh Ram

Reputation: 93

Echo all the columns starting from 3rd column using Batch script

I'm trying to echo and set variable a value by reading a text file. I have a problem that data line contains double quotes in it and the output doesn't come out well as expected.

test.txt file contains:

call m2srun "AB test 1.csv"
call m2srun "AB test 2.csv"
call m2srun "AB test 3.csv"

Code that I've tried:

for /f "tokens=3 delims= " %%a in (test.txt) do echo %%a

Actual Output:

"AB
"AB
"AB

But I'm expecting an output like..

"AB test 1.csv"
"AB test 2.csv"
"AB test 3.csv"

Note: The csv names are not fixed length. It contains spaces and can be any longer.

Upvotes: 0

Views: 879

Answers (1)

Magoo
Magoo

Reputation: 80023

for /f "tokens=2,* delims= " %%a in (test.txt) do echo %%b

May work for you - it depends on whether the first 2 columns may also contain quoted strings that may contain spaces. The * means "the rest of the line following the highest-numbered token specified".

Upvotes: 1

Related Questions