user2373747
user2373747

Reputation:

Batch file for/f doesn't work with all after construction

Let's say I have a simple batch file:

@ECHO off
FOR /f "tokens=3*" %%a in ("f1 f2 f3 f4 f5 f6 f7") do echo %%a

I'm trying to print out f3 f4 f5 f6 f7 but all I get is f3

What's wrong with my batch file?

Upvotes: 2

Views: 353

Answers (2)

Magoo
Magoo

Reputation: 79983

The solution is actually simpler.

@ECHO off
FOR /f "tokens=2*" %%a in ("f1 f2 f3 f4 f5 f6 f7") do echo %%b

Upvotes: 4

user2373747
user2373747

Reputation:

The solution is simple. You just need to add %%a. Now batch file should looks like this:

@ECHO off
FOR /f "tokens=3*" %%a in ("f1 f2 f3 f4 f5 f6 f7") do echo %%a %%b

Where %%a - stands for third token %%b - stands for all tokens after third token.

Upvotes: 3

Related Questions